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

   如何保证设计方案支持低的依赖性、低的变化影响度、增加可重用性?
3.2 耦合的定义Coupling

   耦合: 一个元素与其它元素的联接、感知以及依赖程度的度量

    Measure of how strongly one element is: connected to、 has knowledge of、relies on another element    比较

     Cohesion,内聚: 模块内的操作之间联系紧密的程度

     Coupling,耦合: 两个子模块之间联系的强度

   高耦合带来的问题 Problems with High Coupling

     “牵一发动全身”Forced local changes because of changes in related class

     A依赖B,A与B之间有耦合,一旦B变化了,A就会受影响

   元素孤立是无法理解 Harder to understand in isolation

   元素很难重用 Harder to reuse — drags in more classes
3.3 GRASP rule3: Low Coupling

   Name: Low Coupling

   Problem:

     How to support low dependency, low change impact and increased reuse?

   Solution:

     Assign responsibility so coupling remains low.

       Use this principle to evaluate alternatives

       All other things being equal prefer the low coupling solution
   Note: Information Expert encourages Low Coupling

   Why most secret service (spy) is one-way contact? 为什么特 务工作都是单线联系?
3.4 Discuss: Low Coupling

   低耦合是所有设计决策时自然而然要考虑的原则

    Low Coupling is a principle to keep in mind during all design decisions; it is an underlying goal to     continually consider

   低耦合是一种评估原则,是设计师用来对设计方案进行评价的一种指标

    It is an evaluative principle that a designer applies while evaluating all design decisions

   X与Y存在耦合的情况,例如

     X has an attribute that refers to Y

     X calls on services of Y

     X has a method that references Y (parameter, local variable, or return value)

     X is a direct or indirect subclass of Y

     Y is an interface, and X implements that interface
   低耦合支持类的设计相对独立,减少了变化带来的相互影响

    Low Coupling supports the design of classes that are more independent, which reduces the impact of     change

   低耦合与其他的原则,如信息专家、高内聚必须综合考虑

   不能单独考虑低耦合

     “是药,三分毒”

   继承关系中,子类与父类的耦合非常紧密 A subclass is strongly coupled to its superclass.

     所以, 能用组合的地方不要用继承

   There is no absolute measure of when coupling is too high

     低耦合不具备可操作性!类似“只可意会,不可言传”
   极端情况,类之间没有耦合

     不希望这种情况出现

       because a central metaphor of object technology is a system of connected objects that         communicate via messages

       Too little coupling means we aren’t a “collaborating community of objects”

     这样会形成很差的设计

       产生少量的不内聚、臃肿、行为复杂的对象,承担了全部的工作,这些类 可能独立工作,成为

         一 个个简单的数据仓库

   类之间存在适度的耦合是正常的、必须的

     这样才能产生面向对象系统,其任务是由相互连接的对象通过协作来完成

      to create an object-oriented system in which tasks are fulfilled by a collaboration

      between connected objects
3.4 Discuss:Low Coupling— When Not To

   “背靠大树好乘凉”

     因为大树不会倒、不常变、稳定

   High coupling to stable elements and to pervasive elements is seldom a problem

   e.g. language libraries  For example, a Java J2EE application can safely couple itself to the J

    ava libraries (java.util, and so on)  because they are stable and widespread

7.3 GRASP原则三: 低耦合 Low Coupling的更多相关文章

  1. C# 低耦合 高内聚

    低耦合 loosely Coupling 松散的耦合关系=炮友 couple=夫妻 夫妻=法律约束.家庭.生活.财产.繁衍 炮友:吃喝玩乐,不会产生感情方面的依赖       内聚性 内聚性又称块内联 ...

  2. 面系那个对象开发原则.高内聚.低耦合+Python安装详细教程+print输出带颜色的方法

    面系那个对象开发原则.高内聚.低耦合 软件设计中通常用耦合度和内聚度作为衡量模块独立程度的标准.划分摸块的一个准则就是高内聚低耦合. 这是软件工程中的概念,是判断设计好坏的标准,主要是面向OO的设计, ...

  3. 对C++中高内聚,低耦合原则的理解

    1.C语言是面向过程的语言,采用模块化的设计思想,每个功能划分为一个模块,是以函数为单位的. 2.C++是面向对象的语言,采用类设计的思想,因此C++中的模块是以类为基本单位的. 高内聚,低耦合能够使 ...

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

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

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

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

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

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

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

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

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

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

  9. iOS:CYLTabBarController【低耦合集成TabBarController】

    导航 与其他自定义TabBarController的区别 集成后的效果 项目结构 使用CYLTabBarController 第一步:使用CocoaPods导入CYLTabBarController ...

随机推荐

  1. static final 内部类

    1 static关键字 1.1 static关键字概述类中的属性和方法都是通过创建本类对象调用的,当在调用对象的某个方法时,这个方法没有访问到对象的特有数据时,方法创建这个对象有些多余,可是不创建对象 ...

  2. jQuery Mobile的默认配置项具体解释,jQuery Mobile的中文配置api,jQuery Mobile的配置说明,配置大全

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/xmt1139057136/article/details/35258199 学习jQuery Mob ...

  3. 详细解读html中的Map,area标签

    一.定义 定义一个客户端图像映射.图像映射(image-map)指带有可点击区域的一幅图像. 二.使用 <!--定义一个图像 他的边框为0(border) usemap(指定该图像被用作图像地图 ...

  4. DTCC2019第十届中国数据库技术大会将于5月在北京召开

    作为国内顶级的数据领域技术盛会,10年来,DTCC见证了国内数据库技术的迅猛发展,各种分布式数据库.NoSQL.NewSQL技术异军突起,与Oracle.DB2等分庭抗礼,甚至大有超越之势.在这种背景 ...

  5. Deeplab v3+中的骨干模型resnet(加入atrous)的源码解析,以及普通resnet整个结构的构建过程

    加入带洞卷积的resnet结构的构建,以及普通resnet如何通过模块的组合来堆砌深层卷积网络. 第一段代码为deeplab v3+(pytorch版本)中的基本模型改进版resnet的构建过程, 第 ...

  6. u-boot2010.06移植阶段三--norflash驱动

    2011-03-20 23:06:24 学习笔记: 效果图: 参考步骤: 一,把smdk2410 # 改成apple2440 #  1,在board/samsung/apple2440/apple24 ...

  7. web api使用JObject接收时,报“无法创建抽象类”错误

    https://bbs.csdn.net/topics/391952288 在下列函数中增加  ModelBinders.Binders.Add(typeof(JObject), new JObjec ...

  8. 论文笔记【二】Making Sense of Word Embeddings

    摘要 1.作者提出了一种新的简单有效的方法,用于学习词义嵌入word sense embedding 2.传统的两种方法:(1)直接从语料库中学习词义:(2)依赖词汇资源的语义库 研究方法的创新点:通 ...

  9. python爬虫——论抓包的正确姿势和学好Javascript的重要性(1)

    没事想爬下数据,就入了scrapy坑,跟着https://zhuanlan.zhihu.com/data-factory这篇教程走,中间被小数量的网站坑过,不过还是写出了爬虫~~ 切糕王子:毫无防御, ...

  10. Python Mysql 交互

    Mysql 安装Python模块   Linux: yum install MySQL-python Windos: http://files.cnblogs.com/files/wupeiqi/py ...