PHP Object-oriented abstract class

Source: Internet
Author: User

In the OOP language, a class can have one or more subclasses, and each class has a public method to access its interface as an external code. Abstract methods are introduced to facilitate inheritance.

Master 2 Why?
What is an abstract method?
The method defined in the class without the method body is an abstract method, and the so-called no method body refers to the absence of curly braces and the contents of the method declaration. Instead, simply add a semicolon to the method name to end it. In addition, when declaring an abstract method, add a keyword abstract to decorate it.
What is an abstract class?
As long as there is one method in a class that is abstract, the class is defined as an abstract class, and the abstract class uses the keyword modifier (abstract)

Remember that this class must be declared as an abstract class as long as one method is an abstract method.

Abstract class Demo{public $name; Abstruct function CheckUser (); Abstruct function Checkpassword ();}

  

Note: Abstract classes cannot produce instance objects, so they cannot be used directly.
Abstract methods are used as subclasses of overloaded templates, the definition of abstract class equivalent to define a specification, which requires subclasses to obey, subclass inherits abstract class, the abstract class inside the abstract methods are all implemented, otherwise there are abstract methods in the subclass, then the subclass or abstract class, or can not instantiate class

Abstract method is to subclass the use of inheritance, the definition of abstract class equivalent to define a specification, the specification subclass must be strictly enforced, subclass inherits abstract class, the abstract class inside the abstract method of all implementation, indispensable. You can instantiate only if you have finished writing it all.

PHP Object-oriented abstract class

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.