GRASP原则六: 多态 Polymorphism
   How to handle alternative behaviors based on type 如何处理依据类型不同而有 不同行为的一类需求 ?

     比如,开餐馆

       苏州人喜欢甜、四川人喜欢麻、湖南人喜欢辣,咋处理 ?
1.1 9条GRASP原则

   Information Expert

     responsibilities should be assigned to objects that contain relevant information

   Creator

     the creator of an object is usually an object that contains, or aggregates it

   High Cohesion

     responsibilities of a certain class must be highly related

   Low Coupling

     interdependency between classes should remain low

   Controller

     class which handles external system events

   Polymorphism 多态原则

   Indirection 间接原则

   Pure Fabrication 纯虚构原则

   Protected Variations 隔离变化
1.2 Iteration 2 More Requirement

   第一次迭代结束时,完成了

     当前软件功能测试:单元测试、用户可接受测试、负载测试、可使用性测试等

     必须有客户加入,并给出反馈 Customers engaged in and feedback

     把基线稳定下来,发布内部版本 stabilized baseline internal release

   第二次迭代时,要考虑加入新的功能

     需求变化、业务规则细化、考虑更多的用例

     制定本次迭代的计划活动等

     Ex, Monopoly game

       When a player lands on the Go square, the player receives $200

       When a player lands on the Go-To-Jail square, they move to the Jail square

       When a player lands on the Income-Tax square, the player pays the minimum of $200 or 10%

        of their worth
1.2 Iteration 2 More Requirement

   例如POS系统,第二次迭代时增加另外的需求

     支持多种第三方服务的接口 Support for variations in third-party external services

       计算税费、信用卡授权认证等

     复杂的定价机制 Complex pricing rules

     可插拔的业务规则 Pluggable business rules

     GUI窗口在信息发生变化时得到更新 GUI window updates when information changes

   这些功能点,可能属于前轮迭代同样的用例,但更多的是讨论非功能性需求

   这些需求对领域模型的影响较小

   同样一项功能,原来一种处理方法就可以,现在需要适应多种处理方法,设 计方案该如何支持?

     比如付费:现金、储蓄卡、信用卡、支付宝、微信
1.3 GRASP rule6: Polymorphism(多态)

   Name: Polymorphism(多态)

   Problem:

     如何处理依据类型不同而有不同行为的一类需求?

    How to handle alternative behaviors based on type?

    How to create pluggable software components?

   Solution:

     使用多态操作为依据类型变化的行为 进行职责分配

      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

   Corollary(推论):

     不要去测试对象的类型或者条件逻辑,并以此选择相应的行为

      Do not test for the type of an object and use conditional logic to perform varying alternatives

      based on type

     即,不要使用条件逻辑,而是为不同的类定义相同名字的方法

      That is, don’t use conditional logic, but assign the same name to services (methods) in

      different classes

     不同的类实现了相同的接口、或者有一个共同的父类(继承)The different classes usually

      implement a common interface or are related in an implementation hierarchy with a

      common superclass

7.6 GRASP原则六: 多态 Polymorphism的更多相关文章

  1. 7.9 GRASP原则九: 隔离变化

    GRASP原则九: 隔离变化  Protected Variations  需求一定会变化的!如何做到以系统的局部变化为代价就可以应对这一点?4.1 GRASP rule9: Protected ...

  2. 7.1 通用的职责分配软件原则 GRASP原则一: 创建者 Creator

    1.GRASP原则一: 创建者 Creator  Who should be responsible for creating a new instance of some class 由谁来负责创 ...

  3. 运用GRASP原则来做uml交互类图-------pos机实例

    重要的几个GRASP原则:1.控制器模式   2.创建者模式 (原则)3.信息专家模式(原则) 4. 高内聚 低耦合   这里所说的模式并不是java中针对具体的事件的设计模式 主成功场景的几个操作: ...

  4. 7.8 GRASP原则八: 间接 Indirection

    GRASP原则八: 间接 Indirection  若两个对象直接连接,导致耦合太紧,如何解决?3.1 GRASP rule8: Indirection 间接  Name: Indirection ...

  5. 7.7 GRASP原则七: 纯虚构 Pure Fabrication

    GRASP原则七: 纯虚构 Pure Fabrication  如果依据信息专家原则获得的解决方案不合适,既不想违反低耦合.高内聚,也不想违 反其他的原则, 该如何把职责分配给对象?  左右为难… ...

  6. 7.5 GRASP原则五:高内聚 High Cohesion

    GRASP原则五:高内聚 High Cohesion  How to keep objects focused, understandable and manageable, and as a si ...

  7. 7.4 GRASP原则四:控制器 Controller

    4.GRASP原则四:控制器 Controller  What first object beyond the UI layer receives and co-ordinates (control ...

  8. 7.3 GRASP原则三: 低耦合 Low Coupling

    3.GRASP原则三: 低耦合 Low Coupling  How to support low dependency, low change impact and increased reuse? ...

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

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

随机推荐

  1. vue开发记录--通用时间格式函数

    parseTime(time, fm) { // 解析时间 time: 时间戳或者实践对象 fm: 格式 默认是{y}-{m}-{d} {h}:{i}:{s} if (arguments.length ...

  2. 百度的富文本编辑器UEditor批量添加图片自动加上宽度和高度的属性

    若是没有对编辑器做任何配置直接添加图片的话,显示的html内容如下图所示:它会显示出原图片尺寸 所以必须要对图片的初始显示尺寸做控制:ueditor文件中找到image.js文件 在image.js中 ...

  3. Cartographer源码阅读(6):LocalTrajectoryBuilder和PoseExtrapolator

    LocalTrajectoryBuilder意思是局部轨迹的构建,下面的类图中方法的参数没有画进去. 注意其中的三个类:PoseExtrapolator类,RealTimeCorrelativeSca ...

  4. (转)Golang--使用iota(常量计数器)

    iota是golang语言的常量计数器,只能在常量的表达式中使用. iota在const关键字出现时将被重置为0(const内部的第一行之前),const中每新增一行常量声明将使iota计数一次(io ...

  5. 家庭记账本之微信小程序(五)

    wxml的学习 WXML(WeiXin Markup Language)是框架设计的一套标签语言,结合基础组件.事件系统,可以构建出页面的结构. 用以下一些简单的例子来看看WXML具有什么能力: 数据 ...

  6. Java项目中的异常处理情况

    1. java.lang.nullpointerexception这个异常大家肯定都经常遇到,异常的解释是"程序遇上了空指针",简单地说就是调用了未经初始化的对象或者是不存在的对象 ...

  7. #WEB安全基础 : HTTP协议 | 0x2 HTTP有关协议通信

    IP,TCP,DNS协议与HTP协议密不可分 IP(网际协议)位于网络层,几乎所有使用网络的系统都会用到IP协议 IP协议的作用:把数据包发送给对方,要保证确实传送到对方那里,则需要满足各类条件.两个 ...

  8. C#中哈希表(HashTable)的用法详解以及和Dictionary比较

    1.  哈希表(HashTable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似keyvalue的键值对, ...

  9. jQuery图片无缝轮播

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  10. springboot之jar包部署步骤

    eclipse中: 1.单击整个项目 run as - maven clean - maven install 2.找到项目所在的路径 找到所有的jar包 3.把jar包放到linux对应的文件夹 l ...