PHP: how to reuse code (oop)?

前端 未结 5 674
既然无缘
既然无缘 2021-01-14 00:34

I have studied in php oop and stocked in the concept of reusable code.

I have seen an example like

interface iTemplate
{
    public function setVar         


        
5条回答
  •  醉酒成梦
    2021-01-14 00:58

    Interfaces are usually useful in cases where you want something to be interchangeable. Imagine you'd build a Plugin aware application. You then have the interface iPlugin:

    interface iPlugin {
       public function init();
       /* .. */
    }
    

    and all Plugins would implement that interface. A plugin manager could then easily check if a Plugin implements the interface and call the init() method on it.

提交回复
热议问题