Review Of designed Pattern principle

OutLine:

Explanation in principles of designed pattern and useful designed pattern’s samples, As we known, there are six principles at designing program, no matter what kind of object-oriented programing language. They are Single responsibility principle, Open and Close principle, Dependency inversion principle, Interface segregation principle, Liskov’s substitution principle. Of course, not all of them need to be implemented at the same time wherever reality environment is.

pic below is not relative.

Principles

Open and close principle

Summary:

Software entities (software, modules, functions, or classes) should be open to extension and closed to modification.

How to get understanding of the key principle at software design? Essentially, we can remember that if a module  is available for extension, it will be likely to add new data fields  to it’s data structure, and it should be also easy to plus  new items into the set of function this module contains. Because of that, some modification at proper context is allowed. But, on the other hand, almost all of software are fairly difficult to get known all aspects without a long period of look at every classes, these classes composite the extremely complicated relative composition, for a good software program which is outstanding and excellent at framework’s architecture. The code is assigned and divided into many hierarchies by the logic.

Dependency inversion principle

Summary:

2       following statements below can summarize it:

Firstly, High level module should not depend on low level module, both them should lean on abstraction.

Secondly, Abstraction should not depend on details, details should depend on abstraction.

Abstract code defines the main functionalities their inheritance or concrete module can do and not do, but abstraction couldn’t create new instances which have single responsibility in details. Actually, in the program’s proceeding they are not executed and transferred to their inheritance. Because of the stability of abstractions and fragility of details, if high level and low level module both lean on the abstraction. Whatever and whenever they change, they are also quite easy to have ability to interact with each other very well, since the abstractions they communicate with are unchangeable only! But for the principle, if we want to change the final result of detail. We just initializes and holds a different reference which are both defined with one kind of abstraction. As the result, behaviors will differ from each other.

IOC:

So, what if we can decouple software module from their direct references of relative module. What will happen? That the main cause of why ioc is called ioc. An external module controlling the dependencies will inject the reference to the module that need dependencies. The specialized framework for that is known as inversion of control container.

Single Responsibility Principle

Summary: a class should have only one reason to change

Description: this principle states that if we have two reasons to change a class, that means we have to split the functionality in two classes; each class will handle only one responsibility and on future if we need to make a change we are going to make it in the class which handle it. But if not, when we need to make a change in a class having more responsibilities the change might affect the other functionalities of classes;

Interface segregation principle

Summary:

Clients should not be forced to depend upon some interfaces they don’t use.

This principle teaches us to take care how we write our interfaces. When we write our interfaces we should take care to add only methods that should be there. If we add methods that should not be there the classes implementing the interface will have to implement those methods as well. For example if we create an interface called Worker and add a method lunch break, all the workers will have to implement it. What if the worker is a robot?

Liskov’s substitution principle

Summary:

Derived class should be completely substitutable for their base classes.

This principle is just an extension of the Open Close Principle in terms of behavior. We must make sure that new derived classes are extending the base classes without changing their behavior.

Least knowledge principle

Summary

Just talk with your friends

Advantages:

Reduce the dependencies between objects and reduce software maintenance

Disadvantages:

Result in more "wrapper" classes being written to handle method calls to other components.

This can result in increased complexity and development time as well as decreased runtime performance.

To conclude:

Software design principles represent a set of guidelines that help us avoid having a bad design. But when to determine which design pattern or patterns, we should choose the most suitable patterns corresponding to the different environments. So that will result in some of shortage and disadvantages which don’t follow all principles. But if the final software frameworks can avoid the rigidity, the fragility, the immobility, those defective points could be accepted on programmer even if it is not perfect absolutely.

designed principle的更多相关文章

  1. Atitit.软件开发的几大规则,法则,与原则Principle v3

    Atitit.软件开发的几大规则,法则,与原则Principle  v31.1. 修改历史22. 设计模式六大原则22.1. 设计模式六大原则(1):单一职责原则22.2. 设计模式六大原则(2):里 ...

  2. C#设计模式系列:开闭原则(Open Close Principle)

    1.开闭原则简介 开闭原则对扩展开放,对修改关闭,开闭原则是面向对象设计中可复用设计的基石. 2.开闭原则的实现 实现开闭原则的关键就在于抽象,把系统的所有可能的行为抽象成一个抽象底层,这个抽象底层规 ...

  3. 开放封闭原则(Open Closed Principle)

    在面向对象的设计中有很多流行的思想,比如说 "所有的成员变量都应该设置为私有(Private)","要避免使用全局变量(Global Variables)",& ...

  4. [转]Amazon DynamoDB – a Fast and Scalable NoSQL Database Service Designed for Internet Scale Applications

    This article is from blog of Amazon CTO Werner Vogels. -------------------- Today is a very exciting ...

  5. 最少知识原则(Least Knowledge Principle)

    最少知识原则(Least Knowledge Principle),或者称迪米特法则(Law of Demeter),是一种面向对象程序设计的指导原则,它描述了一种保持代码松耦合的策略.其可简单的归纳 ...

  6. 接口分离原则(Interface Segregation Principle)

    接口分离原则(Interface Segregation Principle)用于处理胖接口(fat interface)所带来的问题.如果类的接口定义暴露了过多的行为,则说明这个类的接口定义内聚程度 ...

  7. 依赖倒置原则(Dependency Inversion Principle)

    很多软件工程师都多少在处理 "Bad Design"时有一些痛苦的经历.如果发现这些 "Bad Design" 的始作俑者就是我们自己时,那感觉就更糟糕了.那么 ...

  8. 里氏替换原则(Liskov Substitution Principle)

    开放封闭原则(Open Closed Principle)是构建可维护性和可重用性代码的基础.它强调设计良好的代码可以不通过修改而扩展,新的功能通过添加新的代码来实现,而不需要更改已有的可工作的代码. ...

  9. 单一职责原则(Single Responsibility Principle)

    单一职责原则(SRP:The Single Responsibility Principle) 一个类应该有且只有一个变化的原因. There should never be more than on ...

随机推荐

  1. 《algorithms Unlocked》读书笔记3——计数排序

    <Algorithms Unlocked>是 <算法导论>的合著者之一 Thomas H. Cormen 写的一本算法基础,算是啃CLRS前的开胃菜和辅助教材.如果CLRS的厚 ...

  2. Qt用Zip压缩文件夹的一些坑

    环境: QT3.3.8 vs2005 QDir dir("/home/Blinux/html"); if ( !dir.exists() ) { //目录不存在 } QString ...

  3. rtx web 分级管理系统 二次开发

    fineui + ASP.NET+rtx server sdk 修正 rtx管理器 修改用户后分级目录出错问题. 加入 单用户多个部门 添加授权关闭部分采用 rsa加密.

  4. 编码与模式------《Designing Data-Intensive Applications》读书笔记5

    进入到第四章了,本篇主要聊的点是编码(也就是序列化)与代码升级的一些场景,来梳理存储之中涉及到的编解码的流程.目前主流的编解码便是来自Apache的Avro,来自Facebook的Thrift与Goo ...

  5. MySQL多Text字段报8126错误(解决过程)

    一.背景 我们的MySQL数据库有一张10个Text的字段的表,还包括几个char和varchar字段,由于业务需求,我在表中加多一个Text字段的时候,插入记录的出现了下面的错误: Row size ...

  6. Chris Richardson微服务翻译:构建微服务之使用API网关

    Chris Richardson 微服务系列翻译全7篇链接: 微服务介绍 构建微服务之使用API网关(本文) 构建微服务之微服务架构的进程通讯 微服务架构中的服务发现 微服务之事件驱动的数据管理 微服 ...

  7. python入门之函数

    为什么要用函数 python的函数是由一个新的语句编写,即def ,def是可执行的语句--函数并不存在,知道python运行了def后才存在. 函数是通过赋值函数传递的,参数通过赋值传递给函数. d ...

  8. Zabbix实战-简易教程--正则(Regxp)

    一.正则表达式(Regx) 1.概述 正则表达式概念就不解释了.请参考:https://en.wikipedia.org/wiki/Regular_expression#POSIX_extended ...

  9. Java多线程与并发编程学习

    一.线程三大特性 多线程有三大特性,原子性.可见性.有序性 1.1 什么是原子性 即一个操作或者多个操作 要么全部执行并且执行的过程不会被任何因素打断,要么就都不执行.一个很经典的例子就是银行账户转账 ...

  10. (转)Android Studio Error:Failed to resolve: com.android.support:appcompat-v7:25.1.0解决方案

    今天不知道为什么导入eclipse项目后就出现了错误,没导入之前是正常使用AS的 Error:(26, 13) Failed to resolve: com.android.support:appco ...