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.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值