Re: Is there a simple way to enforce a private method in a subclass?
| From: | David Harkness | Date: | Tue, 21 Dec 2010 18:16:40 +0000 |
| Subject: | Re: Is there a simple way to enforce a private method in a subclass? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-310203@lists.php.net to get a copy of this message | ||
On Tue, Dec 21, 2010 at 8:36 AM, Richard Quadling <rquadling@gmail.com>wrote:
> If I have an abstract class of Task and I want all subclasses of Task
> to have a private method _runTask, is there a way to enforce this?
>
I cannot think of a reason to force a class to have a specifically-named
*private* method. Since it's private, you cannot call it from outside the
class--not from its superclasses nor any subclasses. Since it cannot be
exposed in the class's API, there's no point in forcing a particular name.
If you are using the Template Method pattern [1], make the method protected.
This allows the superclass that declares the abstract method to call it and
forces its subclasses to implement it given the name you decide.
David
[1] http://c2.com/cgi/wiki?TemplateMethodPattern