微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

General Responsibility Assignment Software Patterns or Principles (GRASP)

Understanding responsibilities is key to good object-oriented design.

---MartinFowler

General Responsibility Assignment Software Patterns or Principles (GRASP)

Pattern/Principle

Description

information

Expert

A general principle of object design and responsibility assignment?

Assign a responsibility to the information expert the class that has the information necessary to fulfill the responsibility.

Creator

Who creates? (Note that Factory is a common alternate solution.)

Assign class B the responsibility to create an instance of class A if one of these is true:

1. B contains A

4. B records A

2. B aggregates A

5. B closely uses A

3. B has the initializing data for A

Controller

What first object beyond the UI layer receives and coordinates ("controls") a system operation?

Assign the responsibility to an object representing one of these choices:

  1. Represents the overall "system," a "root object," a device that the software is running within,or a major subsystem (these are all variations of a facade controller).
  2. Represents a use case scenario within which the system operation occurs (a use-case or session controller)

Low coupling (evaluative)

How to reduce the impact of change?

Assign responsibilities so that (unnecessary) coupling remains low. Use this principle to evaluate alternatives.

High Cohesion (evaluative)

How to keep objects focused,understandable,and manageable,and as a side-effect,support Low coupling?

Assign responsibilities so that cohesion remains high. Use this to evaluate alternatives.

polymorphism

Who is responsible when behavior varies by type?

When related alternatives or behaviors vary by type (class),assign responsibility for the behavior using polymorphic operations to the types for which the behavior varies.

Pure Fabrication

Who is responsible when you are desperate,and do not want to violate high cohesion and low coupling?

Assign a highly cohesive set of responsibilities to an artificial or convenience "behavior" class that does not represent a problem domain concept something made up,in order to support high cohesion,low coupling,and reuse.

Indirection

How to assign responsibilities to avoid direct coupling?

Assign the responsibility to an intermediate object to mediate between other components or services,so that they are not directly coupled.

Protected Variations

How to assign responsibilities to objects,subsystems,and systems so that the variations or instability in these elements do not have an undesirable impact on other elements?

Identify points of predicted variation or instability; assign responsibilities to create a stable "interface" around them.

原文地址:https://www.jb51.cc/javaschema/286386.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐