无思

本BLOG只用于个人资料收藏,内容如非注明,均为转贴资料,无意侵犯版权,特此声明!

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

GRASP stands for Genernal Responsibility Assignment Software Patterns. The author, Craig Larman, is a great teacher and scholar. I have enjoyed working with Craig back in my ObjectSpace days. This table is from his book.

Pattern Description

Expert

Who, in the general case is responsible?

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

Creator

Who creates?

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

  1. B contains A
  2. B aggregates A
  3. B has the initializing data for A
  4. B records A
  5. B closely uses A

Controller

Who handles a system event?

Assign the responsibility for handling a system event message to a class representing one of these choices:

  1. The business or overall organization (a façade controller).
  2. The overall "system" (a façade controller).
  3. An animate thing in the domain that would perform the work (a role controller).
  4. An artificial class (Pure Fabrication) representing the use (a use case controller).

Low Coupling
(evaluative)

How to support low dependency and increased reuse?

Assign responsibilities so that coupling remains low.

High Cohesion
(evaluative)

How to keep complexity manageable?

Assign responsibilities so that cohesion remains high.

Polymorphism

Who, 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, 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 class that does not represent anything in the problem domain, in order to support high cohesion, low coupling, and reuse.

Indirection

Who, 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.

Don't Talk to Strangers
(Law of Demeter)

Who, to avoid knowing about the structure of indirect objects?

Assign the responsibility to a client's direct object to collaborate with an indirect object, so that the client does not need to know about the indirect object. Within a method, messages can only be sent to the following objects:

  • The this object (or self).
  • A parameter of the method
  • A attribute of self.
  • An element of a collection which is an attribute of self.
  • An object created within a method

posted on 2004-10-25 13:13  kavenmo  阅读(496)  评论(0)    收藏  举报