Bkjia.Com Network ProgrammingI recently encountered difficulties in learning the PHP5 interface. The book says it is a way to achieve multiple inheritance, but I still don’t know. How to implement it specifically. There is very little information on the PHP interface on the Internet, so I checked on Java. In fact, they are basically the same. After reading the article "Clarifying Java (Interfaces and Inheritance)", I suddenly realized that I had misunderstood it from the beginning. The so-called multiple inheritance refers to interfaces inheriting classes, not classes inheriting interfaces.
The article mentioned the abstraction of OO, just like the sentence in the article - "Abstraction is to remove the image part", it is very vivid. When I thought about abstraction in the past, I always thought it was difficult to understand. It is abstract, haha, now it is It's easy to understand, and this is exactly what interfaces and abstract classes do.
There are many other points of view in the article that have benefited me a lot, as listed below:
I think the essence of OO is the abstraction of objects.
The role of the interface, in a nutshell, is to mark the type of class. Attributing different types of classes to different interfaces can better manage them.
The meaning of inheritance also lies in abstraction, not code reuse.
After reading this article, I now basically understand how to apply interfaces, abstract classes, and inheritance.
The original text is as follows:
Clarification of Java (Interfaces and Inheritance) My brother who is a second-year graduate student in the School of Computer Science discussed Java with me. When we met, several questions were all about interfaces. What is the use of interfaces? Why use interfaces? When should you use interfaces? I'm glad they didn't ask me how to connect to SQL Server using Java, or how to develop J2EE applications. Such questions are lethal and should be avoided. This year, the School of Computer Science has a graduation project project on J2ME. The students who chose this topic were still studying the java.util.* package with a grimace at the end of May, this and this... sigh.
Most people think that the purpose of interfaces is to replace multiple inheritance. As we all know, Java does not have a multiple inheritance mechanism like C++, but it can implement multiple interfaces. In fact, this is far-fetched. Interfaces and inheritance are completely different things. Interfaces have no ability to replace multiple inheritance, and they have no such obligation. The function of the interface, in a nutshell, is to mark the type of class. Attributing different types of classes to different interfaces can better manage them. I think the essence of OO is the abstraction of objects, and the interface best embodies this. Why we discuss design patterns only for languages with abstract capabilities (such as c++, java, c#, etc.) is because what design patterns study is actually how to abstract reasonably. (Cowboy's famous saying is "Abstraction is to remove the image part", which seems to be a joke, but is actually true).
The most basic design pattern is the Factory pattern. In my recent very simple application, I wanted to try my best to make my program portable between multiple databases. Of course, this involves many problems. Just how to be compatible with SQL of different DBMS is a headache. We might as well simplify the problem first and only consider how to connect different databases.