Re: Is there a simple way to enforce a private method in a subclass?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Dec 21, 2010 at 8:36 AM, Richard Quadling <rquadling@xxxxxxxxx>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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux