Recently, learning the PHP5 interface has encountered difficulties, the book said is a way to achieve multiple inheritance, but I still do not know how to achieve the specific. Check the data on the Internet PHP interface is very few, the Java, in fact, basically almost. Read the packaging machine, "Clarifying the Java (interface and inheritance)" This article just dawned, the original packaging machine I 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 many points in the article 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 abstraction, not code reuse.
After reading this article, now basically understand interface, abstract class, inheritance how to apply.
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, or how to develop EE application, this kind of problem is lethal, avoid 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.
Suppose I have many classes, namely Mysql.java, Sqlserver.java, Oracle.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.java:
Package org.bromon.test;
Import java.sql.*;
public class Mysql implements DB
{
Private String url= "Jdbc:mysql: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
}
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