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 principleSummary:
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 principleSummary:
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 PrincipleSummary: 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 principleSummary:
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 principleSummary:
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 principleSummary
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.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)