Learning the PHP interface_PHP tutorial
Recently I encountered difficulties while learning the PHP(as the current mainstream development language)5 interface. The book said it is a way to achieve multiple inheritance, but I still don’t know how to do it. accomplish. I looked up php (as the current mainstream development language) interface information on the Internet. There was very little information on it, so I checked 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 abstraction of OO was mentioned in the article. Just like the sentence in the article - "Abstraction is to remove the image part". It is very vivid. When I thought about abstraction, 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:
The essence of OO, I think, 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 is 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:
Clarifying Java (Interfaces and Inheritance) My brother, 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 that they didn't ask me how to connect to SQL server(a powerful database platform on the WINDOWS platform) 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.
Suppose I have many classes, namely MySQL (the best combination with PHP) .java, SQLServer.java, Oracle (large website database platform) .java , DB2.java, they connect to different databases respectively, uniformly return a Connection object, and all have a close method for closing the connection. You only need to select different classes for your DBMS, and you can use it. But what database will my user use? I don't know, what I hope is to modify 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 only defines two methods without any meaningful code. The specific code is given by the class that implements this interface, such as MySQL (the best combination with PHP) .java:
Package org.bromon.test;
import java.sql.*;
public class MySQL(The 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)
{
//Code to connect to the database
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
