dousu1916 2011-12-19 15:41
浏览 47
已采纳

php oop接口或抽象类

Can anyone give me an example of the following desired OOP structure please.

I want a main class (super class) (interface or abstract class?) where all the other classes that are extending from it can have their functions called from instances of the main super class.

e.g.

class mainSupoerClass() {

}

class doWork exends mainSupoerClass(){
    public function addEntity(){
        //do stuff for entity
    }
}

I want be able to do this:

$data = new mainSupoerClass;
$data->addEntity();  (doesnt belong to this class but its fetching the function from doWork class)

Can anyone give me a start on the correct OOP structure to carry out this work?

  • 写回答

4条回答 默认 最新

  • douxie1692 2011-12-19 15:45
    关注

    In simple terms, you can't. You have to instantiate the extended class and you'll get all functions within the instantiated class and also the parent class/classes.

    Is there any reason you need this to be done this way?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败