面向对象软件设计原则

    最近,公司老总推荐一篇文章,关于软件设计原则的,感觉不错,记录以下供以后查阅。

这些设计原则,不仅仅是指软件开发...

    Don’t Repeat Yourself (DRY)

    Keep It Simple, Stupid (KISS)

    Program to an interface, not an implementation 

    Command-Query Separation (CQS)  – 命令-查询分离原则 

    You Ain’t Gonna Need It (YAGNI)    <you are not going to need it>

    Law of Demeter <Principle of Least Knowledge>

            

        对于对象 ‘O’ 中一个方法’M',M应该只能够访问以下对象中的方法:

        对象O;
         1 与O直接相关的Component Object;
         2 由方法M创建或者实例化的对象;
         3 作为方法M的参数的对象。

    在《Clean Code》一书中,有一段Apache framework中的一段违反了LoD的代码:

final String outputDir = ctxt.getOptions().getScratchDir().getAbsolutePath(); 

     面向对象的S.O.L.I.D 原则
       Single Responsibility Principle (SRP) – 职责单一原则
       Open/Closed Principle (OCP) – 开闭原则
       Liskov substitution principle (LSP) – 里氏代换原则
       Interface Segregation Principle (ISP) – 接口隔离原则
       Dependency Inversion Principle (DIP) – 依赖倒置原则

    Common Closure Principle(CCP)– 共同封闭原则

    Common Reuse Principle (CRP) – 共同重用原则

    Hollywood Principle – 好莱坞原则

    High Cohesion & Low/Loose coupling & – 高内聚, 低耦合

    Convention over Configuration(CoC)– 惯例优于配置原则

    Separation of Concerns (SoC) – 关注点分离

    Design by Contract (DbC) – 契约式设计

    Acyclic Dependencies Principle (ADP) – 无环依赖原则


猜你喜欢

转载自argel-lj.iteye.com/blog/1337028