7.2 GRASP原则二:信息专家 Information Expert

2、GRASP原则二:信息专家 Information Expert
   What is a general principle of assigning responsibility to objects?

    为一个对象 分配职责的一般原则是什么?

   “鸡鸣狗盗” 战国时候,齐国的孟尝君喜欢招纳各种人做门客,号称宾客三千….
2.2 GRASP rule2: Information Expert

   Name: Information Expert (信息专家)

   Problem:

     What is a general principle of assigning responsibility to objects?

   Solution:

     Assign responsibility to the class that has the information necessary to fulfill responsibility
   Information

     an object's own state,

     about other objects, the world around an object,

     information the object can derive,

     and so forth

   Answer to Mini exercise 2
2.3 Information Expert — How to?

   步骤

     1)Clearly state the responsibility

     2)Look in Design Model for relevant classes

     3)Else look in Domain Model and create design classes

   信息专家的优点

     封装性 Encapsulation

       对象充分利用自身的信息 objects support their own information

       支持低耦合 supports low coupling

     系统行为分布到不同的类 Behavior is distributed across classes

       支持高内聚 supports high cohesion

posted @ 2019-03-18 05:20  otr  阅读(671)  评论(0编辑  收藏  举报