[5] object-oriented design principles

Five basic principles
Single responsibility principle SRP (Single Responsibility Principle)
  It refers to a class of functions to be single, not all-inclusive.
 
Open Closed Principle OCP (Open-Close Principle)
  A module in scalability should be open, but in terms of change should be closed.
  For example: a network module, only the original server function, and now want to join the client function, then it should be in the code without modifying the server function of the premise, it is possible to increase the code that implements the client function
  This requires early in the design, it should be separated from the server and the client, the public part of the abstract.
 
Alternatively principle (the Liskov Substitution Principle LSP)
  Subclasses should be able to replace the parent class and appear anywhere in the parent class can appear.
  For example: the company engage in an annual party, all employees can participate in the drawing, so whether it is new or old staff employees, regardless of headquarters employees or expatriates, all should be able to participate in the drawing, otherwise the company would discord.
 
Dependent principle (the Dependency Inversion Principle DIP)
  In particular abstract dependent, dependent on the lower layer an upper layer.
  Suppose B is lower than the module A, B but need to use the function A, this time, B should not be used directly in the concrete class A: and should define an abstract interface consisting of B, A to achieve this by the abstract interface, B using only the abstract interface: this achieves the object dependency inversion, B also lifted dependence of a, which in turn is dependent on the definition of a B abstract interface.
  Upper module by the lower module is difficult to avoid dependence, if B is also directly dependent on implement A, then it may result in a circular dependency.  
 
Interface separation principles (the Interface Segregation Principle ISP)
  Abstract interface between the modules through isolated, rather than through a specific class of strong coupling together

Guess you like

Origin www.cnblogs.com/zuixinxian/p/11276363.html