Overview of PHP object-oriented design principles

韦小宝
Release: 2023-03-17 14:38:01
Original
1833 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!