日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

7.5 GRASP原则五:高内聚 High Cohesion

發(fā)布時間:2023/12/2 58 豆豆
生活随笔 收集整理的這篇文章主要介紹了 7.5 GRASP原则五:高内聚 High Cohesion 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

GRASP原則五:高內(nèi)聚 High Cohesion
  ? How to keep objects focused, understandable and manageable, and as a side effect support Low Coupling?

    如何使對象功能專注、可理解、可管理,同時又支持 低耦合?
5.1 GRASP rule 5:High Cohesion

  ? Name:High Cohesion 高內(nèi)聚

  ? Problem:

    ? How to keep objects focused, understandable and manageable, and as a side effect support Low Coupling?

  ? Solution:

    ? Assign responsibility so cohesion remains high 分配職責時保證高內(nèi)聚

  ? Dosage(用法):

    ? Used as an evaluation tool 用作評價工具

    ? 更多的是一種理念,沒有具體的可操作原則
5.2 Cohesion Defined

  ? 衡量概念之間相關度的兩個指標

    ? Cohesion,內(nèi)聚:模塊內(nèi)元素之間聯(lián)系緊密的程度,比如,一個類內(nèi)部的操作之間

    ? Coupling,耦合:兩個模塊之間聯(lián)系的強度

  ? 內(nèi)聚的“最佳實踐”

    ? 一個對象完成的功能不要太多 small number of responsibilities

    ? 這些功能都是同一類別的 highly related responsibilities

    ? 例如,教授:主要任務就是教學;研究員:主要任務是科研

  ? 評判練習,哪個更內(nèi)聚

    ? 一個類有2000行源代碼100個方法

    ? 另一個類有200行源代碼10個方法

    ? 誰能保證任務重的對象在完成功能時不會引用到類外部的資源(增加了耦合度)

  ? 比喻: “不是一家人,不進一家門”

    ? “人” compared to “職責、操作”

    ? “門” compared to “模塊、類”
5.4 Discuss: Cohesion

  ? 類低內(nèi)聚的具有癥狀 A class with low cohesion

    ? 做了許多相互無關的工作 does many unrelated things

    ? 做了太多工作 does too much work

  ? 類低內(nèi)聚的的原因 Low cohesion classes often represent

    ? 大粒度的抽象 a very large grain of abstraction

    ? 做了太多本應該委托給其他類去做的工作 have taken on responsibilities that should have been delegated to other objects

  ? 類低內(nèi)聚的問題

    ? 難以理解 Hard to understand

    ? 難以重用 Hard to reuse

    ? 難以維護 Hard to maintain

    ? 沒有穩(wěn)定的時刻,總是在修改 (通常都會高耦合)
小結(jié)

  ? 高內(nèi)聚的類

    ? 有較少數(shù)量的操作,操作的性質(zhì)基本一致,不會做太多的事情

    ? 如果同類別的工作太多,則會定義新的類分擔任務,相互間合作

  ? 高內(nèi)聚的類有許多有點

    ? 易于維護

    ? 易于理解

    ? 易于重用

  ? 高內(nèi)聚也是一種評估性原則,用于評估所有的設計決策是否合適

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

轉(zhuǎn)載于:https://www.cnblogs.com/mayZhou/p/10550041.html

總結(jié)

以上是生活随笔為你收集整理的7.5 GRASP原则五:高内聚 High Cohesion的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。