Home > Backend Development > PHP Tutorial > OOP Thought and Design

OOP Thought and Design

巴扎黑
Release: 2023-03-02 18:38:02
Original
1946 people have browsed it

OOP - Object-oriented programming. OOP thinking refers to the idea of ​​object-oriented itself. OOP design does not mean encapsulating all code into classes. Because, if that, that only refers to object-oriented programming.

OOP - Object-oriented programming is just a practice. OOP thinking is fundamental. What matters is not the approach, but the actual goal to be achieved.总 Java language always can always achieve object -oriented goals. The reason is quite simple. That's because of the limitations of the language itself.

Everything in JAVA needs to be in a class. Standalone functions outside the class are not allowed. Design patterns exist only because of the emergence of JAVA. From this point of view, JAVA has changed the thinking of the software world.

The goal of OOP is to make the code comply with SOLID principles. These principles are introduced at the beginning of any book on design patterns.

But this is a theoretical goal. The actual goal is to answer why we do what we do. Because we always don’t know the future. We don't know how demand will change. We may only be able to provide a simplified version for a limited time today. But it will definitely be expanded in the future. What we have done may have covered everything today, but one day we will find that there is another component that has not been taken into account.

If there is no object-oriented approach, then we have completed it with the simplest switch case structure. Because of this, we had to rework our core code. However, if our code complies with the SOLID principle, then all we have to do is add a new CLASS to the existing code.

It’s not difficult to find out: the plug-in idea originated from OOP. So, if we look at OOP at this time, it is not just a matter of encapsulating scattered code into classes.

We need to follow the SOLOD principle and clarify what is abstract and what is concrete. We only provide limited problem-specific code, but they all rely on the overall abstraction. If there are new specific problems of the same type, we just need to add classes. This is the core of the idea of ​​design patterns.

OOP design is far from that. Code readability and maintainability also depend on the directory and documentation. On the surface, this is not an important detail. But reality is extremely important. Especially the design of core modules for a certain problem, or the design of a PHP development framework. The readability of a directory, or whether it conforms to OOP, largely determines how quickly people understand it and how willing they are to accept it. For example, the directory structure of SYSMFONY is not very good. Although it is an old brand, it occupied a large market in the early stage. But the market is still divided by some new frameworks. Looking back, those codes were not very well designed, such as KOHANA, but CI was quite easy to accept, and it was also related to its directory structure. This is also the reason why some domestic frameworks can be accepted by users. It's not just because it's the Chinese version.

It can be seen that the idea of ​​OOP design is not just in terms of code, but in all aspects of architecture and design.的 The problem of the PHP framework is mostly because of the open source system that people who have not really experienced the oversized projects have sufficient experience as architects. This is quite excusable. However, if an enterprise does open source, after many years of operation, the system will become larger and more complex, and it will be a tragedy if it cannot have a clear architecture that is easy to use and easy to maintain.

        some say that these companies can take advantage of this and make money for customers who need secondary development. In fact, earning this kind of money is always limited. Because, a good core architecture will bring about real software industrialization. And there will be significant cost savings.来 In fact, when you talk back, the development framework is actually quite simple. It’s so simple that it can be summarized in one or two sentences: First, provide different class libraries for users to call, allowing users to write less code. The second is to allow users to easily add the plug-ins they need and reduce user development. These are actually related systems that call each other. In the MVC system, the pure OOP framework, the latter is the framework calling the user's code. In this aspect, the most prominent one is the user interface component. PHP has a large number of frameworks in this category. But they are all very elementary. None can compare with FCS or TYPESTRY in JAVA. Some beginners can even publish a tag engine that is less than 200KB. You can imagine it without looking at the code. There will never be a design pattern, let alone SOLID principles. Then, expansion and maintenance will be quite big problems.

So we thought about how many Internet companies have their websites powered by PHP. On the surface, PHP seems to reduce costs, but to what extent can it be reduced? The key is still from OOP code to OOP architecture. The level of OOP architecture determines the efficiency and cost of development by the technical department.


Related labels:
oop
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