7.7 GRASP原则七: 纯虚构 Pure Fabrication

GRASP原则七: 纯虚构 Pure Fabrication
   如果依据信息专家原则获得的解决方案不合适,既不想违反低耦合、高内聚,也不想违 反其他的原则,

    该如何把职责分配给对象?

   左右为难….
2.1 GRASP rule7: Pure Fabrication 纯虚构

   Name: Pure Fabrication

   Problem: 依据一些原则(比如,信息专家)获得的解决方案不合 适的情况下,既不想违反低耦合、高

    内聚,也不想违反其他的原则, 如 何 把 职 责 分 配 给 对 象 ?

    What objects should have the responsibility, when you do not want to violate High Cohesion

    and Low Coupling, or other goals, but solutions offered by Expert (for example) are not appropriate?

   Solution: 把高度内聚的职责分配给虚构出来的一个类,这个类在 领域模型里没有对应的概念

    Assign a highly cohesive set of responsibilities to an artificial or convenience class that does

    not represent a problem domain concept – something made up to support high cohesion,

    low coupling, and reuse

   推论: 这种方式在有的场合能起到支持低耦合、高内聚、重用的效果
2.3 纯虚构原则讨论

   应用纯虚构原则

     A Pure Fabrication should be designed with high potential for reuse

       – The responsibilities must remain small and cohesive

       Reuse potential should increase

     Many existing GOF patterns are examples of Pure Fabrication

     多数情况下是按功能类定义新的类,所以,是一种“功能为中心的”对象

      It is partitioned on related functionality, and so is a kind of function-centric object

     如果功能的相关性比较高的话,满足高内聚 High Cohesion is supported if functions are highly related    风险

     宽泛地说,虚构对象分为两类 design of objects can be broadly divided into two groups:

       代表性概念为主的分解 representational decomposition, ex, sale

       行为性概念为主的分解 behavioral decomposition, ex, PersistentStorage

     可能导致面向功能或者面向过程的分析/设计,然后用OO语言去实现

posted @ 2019-03-18 07:13  otr  阅读(954)  评论(0编辑  收藏  举报