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
}

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。


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

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
