The examples in this article describe the PHP abstract methods and abstract classes. Share to everyone for your reference, specific as follows:
What is an abstract method?
A method that is defined within a class without a method is an abstract method that does not have curly braces and the contents of the method declaration, plus the keyword abstract when declaring the abstract method.
For example:
Abstract function fun1 ();
Abstract function fun2 ();
As long as there is an abstract method in the class, the class is defined as an abstract class.
Abstract classes also need to be decorated in abstract.
Abstract classes can have methods and member properties that are not abstract.
But as long as there is an abstract method, the class must be defined as an abstract class.
How does an abstract class work? The most important point is the abstract class, cannot produce the instance Object!
Defining an abstract class is equivalent to defining a specification! This specification requires subclasses to follow! After the subclass inherits the abstract class, the abstract method in the abstract class is implemented according to the needs of the subclass.
Subclasses must implement all abstract methods in an abstract class, or there are abstract methods in subclasses, subclasses or abstract classes, or not instantiated!
<?php
abstract class demo{
var $test;
Abstract function fun1 ();
Abstract function fun2 ();
function Fun3 () {
...}}
Class Test extends demo{
function fun1 () {
...
}
function fun2 () {
...}}
$test = new test ();
? >
More about PHP Interested readers can view the site topics: "PHP object-oriented Program Design Primer", "PHP basic Grammar Introductory Course", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Array" operation Skills Encyclopedia, " Summary of PHP string usage, Introduction to PHP+MYSQL database operations, and a summary of PHP common database operations Tips
I hope this article will help you with the PHP program design.