Oop-PHPinterface is expensive. Use abstract classes instead of interfaces.

Source: Internet
Author: User
In "Best Practices for Android and PHP development", we can see that "PHP interface is very expensive. Please use abstract classes instead of interfaces as much as possible". This is a bit dizzy and requires specific analysis. In "Best Practices for Android and PHP development", we can see that "PHP interfaces are expensive. Please use abstract classes instead of interfaces as much as possible". This is a bit dizzy for specific analysis.

Reply content:

In "Best Practices for Android and PHP development", we can see that "PHP interfaces are expensive. Please use abstract classes instead of interfaces as much as possible". This is a bit dizzy for specific analysis.

The performance is high and low. I cannot analyze it here. I don't think it is necessary to analyze it.
Abstract classes have different purposes than interface classes. They are used differently.
An interface class defines some interface standards and is not implemented. The class that implements the interface class must express that I have methods defined in the interface class, but the specific implementation methods vary.
Abstract class, which can implement specific methods and inherit the class of the abstract class, I use the abstract class method, including the specific implementation (the subclass can also override the method to overwrite the parent class)

Note: What I'm talking about isImplementation Interface Class,Inherit abstract classesIn PHP, onlyExtendsA parent class (including abstract classes), but canImplementsMultiple interface classes, which are differentiated in usage.

I have never read the book you mentioned. I think it is necessary to have your own distinction and use it properly.
There is a small difference in real-time performance, but it is acceptable to sacrifice a little performance for the maintainability of the program.

$ ClassName = "xxx"; $ instance = new $ className;

Is this an interface or an 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.