Home  >  Article  >  Backend Development  >  Overview of PHP object-oriented design principles

Overview of PHP object-oriented design principles

韦小宝
韦小宝Original
2017-11-15 11:04:201735browse

Object-orientedDesign principles were born to support maintainability and reuse. These principles are contained in many design patterns, They are guiding principles summarized from many design solutions. Understanding Object-oriented design principles helps us understand design patterns. Design descriptions are all derived from Object-oriented design principles


Object-oriented design principle of single responsibility principle

Answer: A class is only responsible for the corresponding responsibilities in one functional area, or it can Definition: For a class, there should be only one reason for its change

Object-oriented design principles of opening and closing principles

Answer: A software entity such as a class , modules and functions should be open for extension and closed for modification. That is, the software entity should try to be extended without modifying the original code.

Object-oriented design principles: Liskov substitution principle

Answer: All places that reference a base class (parent class) must be able to transparently use objects of its subclasses .

Object-oriented design principle Dependency Inversion Principle

Answer: Abstraction should not depend on details, details should depend on abstraction. In other words, program to the interface, not to the implementation.

Object-oriented design principles of interface isolation principle

Answer: Use multiple specialized interfaces instead of a single general interface, that is, the client should not rely on those It doesn't require an interface.

Object-oriented design principles of composition and reuse

Answer: Try to use object combination instead of inheritance to achieve the purpose of reuse

Object-oriented design principles: Dimit's Law

Answer: A software entity should interact with other entities as little as possible

Related recommendations :

PHP object-oriented design and data accessible design

##About object-oriented PHP - the definition of classes, the instantiation operations of objects, and the special usage of constructors and destructors - WORSHIP Yasa



The above is the detailed content of Overview of PHP object-oriented design principles. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn