General Responsibility Assignment Software Patterns or Principles (GRASP)

前端之家收集整理的这篇文章主要介绍了General Responsibility Assignment Software Patterns or Principles (GRASP)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Understanding responsibilities is key to good object-oriented design.@H_502_1@

---MartinFowler@H_502_1@

General Responsibility Assignment Software Patterns or Principles (GRASP)@H_502_1@

Pattern/Principle@H_502_1@

Description@H_502_1@

Information@H_502_1@

Expert@H_502_1@

A general principle of object design and responsibility assignment?@H_502_1@

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

Creator@H_502_1@

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

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

1. B contains A@H_502_1@

4. B records A@H_502_1@

2. B aggregates A@H_502_1@

5. B closely uses A@H_502_1@

3. B has the initializing data for A@H_502_1@

Controller@H_502_1@

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

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

  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)@H_502_1@

How to reduce the impact of change?@H_502_1@

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

High Cohesion (evaluative)@H_502_1@

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

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

Polymorphism@H_502_1@

Who is responsible when behavior varies by type?@H_502_1@

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.@H_502_1@

Pure Fabrication@H_502_1@

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

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.@H_502_1@

Indirection@H_502_1@

How to assign responsibilities to avoid direct coupling?@H_502_1@

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

Protected Variations@H_502_1@

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?@H_502_1@

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

猜你在找的设计模式相关文章