recently encountered difficulties in learning Php 5 interface, which is a way to achieve multiple inheritance, But I still don't know exactly how to do it. Check the internet php (as the current mainstream development language) interface information is very small, the Java, in fact, basically almost. After reading the clarification of Java (interface and inheritance) This article just dawned on me, originally I began to understand the wrong, the so-called multiple inheritance refers to the interface inheritance class, rather than the class inheritance interface.
The abstract of Oo is mentioned in the article. As the article in the sentence-"abstract is the part of the pumping", very image, the previous thought of abstraction is always considered difficult to understand, abstract well, haha, now it is easy to understand, this is also the interface and abstract class to do things. There are a lot of ideas in
articles that I have benefited from, listed below:
The essence of OO, I think, is the abstraction of objects. The function of the
interface, Word, is the category of the Flag class (Type of Class). By attributing different types of classes to different interfaces, you can better manage them. The meaning of
inheritance is also abstract, not code reuse.
After reading this article, we now basically understand interfaces, abstract classes, and how inheritance should be applied.
The original text reads as follows:
Clarifying Java (interface and inheritance) Computer College grind two brothers and I discuss Java, a meeting, a few questions are all about interfaces, what is the use of interfaces? Why should I use an interface? When should I use an interface? I'm glad they didn't ask me. java How to connect SQL Server(a powerful database platform on the Windows platform), or how to develop Java EE application, this kind of problem has the lethality, avoids the auspicious. This year, the University of Computer science has a graduation project is to do J2ME, selected this topic students in the end of May are still face study java.util.* This bag, this ... Alas.
Most people think that the meaning of interfaces is to replace multiple inheritance. It is well known that Java does not have multiple inheritance mechanisms like C + +, but it can implement multiple interfaces. In fact, this is very far-fetched, interface and inheritance is a completely different thing, the interface does not have the ability to replace multiple inheritance, there is no obligation. The function of the interface, Word, is the category of the Flag class (Type of Class). By attributing different types of classes to different interfaces, you can better manage them. The essence of Oo, I think, is the object of abstraction, the most embodiment of this is the interface. Why we discuss the design patterns are only for the language with the abstract ability (such as C + +, Java, C #, etc.), because the design pattern is studied, in fact, is how to the rational abstraction. (Cowboy's famous saying is "Abstract is the part that pulls out the image", seemingly ridicule, actually is the rationale).
The most basic design pattern is the Factory mode (Factory), in my recent simple application, I want to try my best to allow my program to migrate across multiple databases, of course, this involves a lot of problems, and how to be compatible with the different DBMS SQL makes a person headache. We might as well simplify the issue and consider only how to connect to different databases.
Let's say I have a lot of classes that are MySQL(the best combination of PHP). Java, Sqlserver.java, Oracle(large Web site database platform). Java, Db2.java, they connect to separate databases, return a Connection object uniformly, and have a close method for closing the connection. You just need to select a different class for your DBMS, but what database does my user use? I don't know, I want to change the code as little as possible to meet his needs. I can abstract the following interface:
Package org.bromon.test;
public interface DB
{
Java.sql.Connection opendb (String url,string user,string password);
void Close ();
}
This interface defines only two methods, without any meaningful code, and the specific code is given by the class that implemented the interface, such as MySQL(the best combination of PHP). Java:
Package org.bromon.test;
Import java.sql.*;
public class MySQL(best combination with PHP) implements DB
{
Private String url= "Jdbc:mysql(best combination with PHP): Localhost:3306/test";
Private String user= "root";
Private String password= "";
Private Connection Conn;
Public Connection opendb (Url,user,password)
{
Code to connect to a database
}