Oop-php interface very expensive. Use abstract classes instead of interfaces

Source: Internet
Author: User
Keywords Php interface interface OOP
As seen in the best practices for Android and PHP development, "PHP interface costs very high please use abstract classes instead of interfaces as much as possible," a bit dizzy, for specific analysis.

Reply content:

As seen in the best practices for Android and PHP development, "PHP interface costs very high please use abstract classes instead of interfaces as much as possible," a bit dizzy, for specific analysis.

Performance level, I can not analyze this side, I do not think it is necessary to analyze.
Abstract classes, and interface classes appear to be different, and they are used differently.
interface classes, which are defined by some interface standards, are defined only as not implemented. The class that implements the interface class, to express, I have the method of definition in the interface class, but the concrete implementation way is different.
Abstract class, is can implement concrete methods, inherit the class of abstract class, I use the method of abstract class, including concrete implementation (subclass can also override method, Overwrite parent class)

Note that I am saying that 实现接口类 , 继承抽象类 in PHP only extends one parent class (including abstract classes), but can be implements more than one interface class, this is in the usage of the distinction.

I have not seen the book you mentioned, I think, to have their own discrimination, reasonable use.
There is a small difference in the real-time performance, but for the maintainability of the program, sacrificing a little bit of performance is also acceptable.

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

Is this a 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.