简体   繁体   中英

PHP singleton pattern - question about extends

Just a quick question. I understand that Singleton patterns can be extended and that inheritance is applied. I was just wondering if I called a base class and then a extended class is there additional overhead than if I just called the extended class by itself?

If what you're talking about is something like

class BaseSingleton {
    public function DoSomething() {
    }
}

class ExtendedSingleton extends BaseSingleton {
    public function DoSomething() {
        parent::DoSomething();
    }
}

then yes, there is overhead in the call being forwarded from the child class's DoSomething() to the parent class's. If ExtendedSingleton does not redefine DoSomething() , though, there is no additional overhead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM