码迷,mamicode.com
首页 > 其他好文 > 详细

designed principle

时间:2017-07-08 11:16:47      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:res   different   relative   ase   term   friends   other   void   outline   

技术分享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.

 

技术分享

 

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

标签:res   different   relative   ase   term   friends   other   void   outline   

原文地址:http://www.cnblogs.com/daniel123/p/7136028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!