美文网首页
(设计模式原则)迪米特原则

(设计模式原则)迪米特原则

作者: 乔什华 | 来源:发表于2016-10-01 14:37 被阅读0次

    Definition

    • Each unit should have only limited knowledge about other units: only units "closely" related to the current unit.
    • Each unit should only talk to its friends; don't talk to strangers.
    • Only talk to your immediate friends.

    Advantages

    The advantage of following the Law of Demeter is that the resulting software tends to be more maintainable and adaptable. Since objects are less dependent on the internal structure of other objects, object containers can be changed without reworking their callers.

    Disadvantage

    Although the LoD increases the adaptiveness of a software system, it may also result in having to write many wrapper methods to propagate calls to components; in some cases, this can add noticeable time and space overhead.

    Reference

    Law of Demeter - Wikipedia, the free encyclopedia

    相关文章

      网友评论

          本文标题:(设计模式原则)迪米特原则

          本文链接:https://www.haomeiwen.com/subject/pbbryttx.html