PHP interface learning _ PHP Tutorial

Source: Internet
Author: User
PHP interface learning. I recently encountered difficulties in learning the php (as a mainstream development language) 5 interface. The book says it is a way to implement multi-inheritance, but I still don't know how to implement it. I recently encountered difficulties in learning the php (as a mainstream development language) 5 interface. The book says it is a way to implement multi-inheritance, but I still don't know how to implement it. There is very little information about the php (as the mainstream development language) interface on the internet. I checked java, which is basically the same. After reading the article "clarifying Java (interfaces and inheritance)", I suddenly realized that I had an incorrect understanding at the beginning. The so-called multi-inheritance refers to the interface inheritance class, not the class inheritance interface.
The article mentions the OO abstraction, just as the sentence in the article -- "abstraction is the part of the image", which is very Image. it is always hard to understand and abstract in the past, haha, now it's easy to understand. this is exactly what interfaces and abstract classes need to do.
I also benefited from many points in the article, as listed below:
The essence of OO, I think, is the abstraction of objects.
The function of an interface, in a word, is the type of class ). You can better manage different types of classes by assigning them to different interfaces.
The significance of inheritance also lies in abstraction, rather than code reuse.
After reading this article, I have basically understood how to apply interfaces, abstract classes, and inheritance.

The original article is as follows:
Clarify that the brother of Java (interface and inheritance) Emy of computer science discussed Java with me. when I met, I asked a few questions about interfaces. what is the use of interfaces? Why use interfaces? When should I use the interface? Fortunately, they didn't ask me how Java connects to SQL server (a powerful database platform on WINDOWS), or how to develop J2EE applications. such problems are lethal and avoided. This year, I graduated from the Computer Science Institute with a design subject of j2-based. at the end of May, the students who chose this subject were still studying java. util. *. this package ...... Alas.

Most people think that the meaning of an interface is to replace multiple inheritance. As we all know, Java does not have the multi-inheritance mechanism like c ++, but it can implement multiple interfaces. In fact, this is very far-fetched. interfaces and inheritance are completely different. interfaces do not have the ability to replace multiple inheritance, and they do not have this obligation. The function of an interface, in a word, is the type of class ). You can better manage different types of classes by assigning them to different interfaces. The essence of OO, I think, is the abstraction of objects, the interface that best reflects this point is. Why do we discuss that the design patterns are only for languages with abstract capabilities (such as c ++, java, and c #) because the design patterns are studied, it is actually how to reasonably abstract. (Cowboy's famous saying is that "abstraction is the part of image extraction". it seems ridiculous, but it is actually the most reasonable ).

The most basic design pattern is the Factory Pattern. in a very simple application recently, I want to try to Port my program among multiple databases. of course, this involves many problems. it is a headache to be compatible with the SQL statements of different DBMS. We may want to simplify the problem and only consider how to connect to different databases.

Suppose I have many classes, respectively MySQL (the best combination with PHP ). java, SQLServer. java and Oracle (large website database platform ). java and DB2.java connect to different databases, and return a Connection object in a unified manner. they all have a close method to close the Connection. You only need to select different classes for your DBMS. but what Database does my user use? I don't know. I want to modify the code as little as possible to meet his needs. I can abstract the following interfaces:
Package org. bromon. test;
Public interface DB
{
Java. SQL. Connection openDB (String url, String user, String password );
Void close ();
}

This interface only defines two methods without any actual code. the specific code is provided by the class implementing this interface, such as MySQL (the best combination with PHP ). java:

Package org. bromon. test;
Import java. SQL .*;
Public class MySQL (best combination with PHP) implements DB
{
Private String url = "jdbc: MySQL (the best combination with PHP): localhost: 3306/test ";
Private String user = "root ";
Private String password = "";
Private Connection conn;
Public Connection openDB (url, user, password)
{
// Database connection code
}

Middleware (as the mainstream development language) 5 interfaces encountered difficulties. The book says it is a way to implement multi-inheritance, but I still don't know how to implement it ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.