[PHP] Implementing optional methods in a concrete class, but calling them from an abstract class.

2010-11-01 Thread Richard Quadling
Hi.

I have an abstract base class (call it genericServiceHandler).

I have concrete classes (FaxService, EmailService).

The genericServiceHandler is watching for commands from an external
source. The commands will always be one of a fixed set, no matter what
the concrete service is. They are Pause, Continue, Start, Stop,
Shutdown, PreShutdown.

The genericServiceHandler has no need to process the commands. It only
receives them and maybe dispatches them to the concrete class.

The concrete class doesn't have to implement handlers for all of the
commands, though, at a minimum, onStart() would be pretty much
essential.


My question relates to how should I code this.

Should the base class have empty protected stubs to allowing the
concrete class to override them via inheritance?

Should I use __call() to capture the non-existing methods and use LSB
to allow the concrete class to get the commands?


I need to document this (phpdoc) to allow those designing the actual
services know what to implement.

The empty stubs certainly seems the easiest as I can block the scope
to protected and include a full reasoning on when the method will be
called (not all commands are applicable at all times).

Using __call() can be documented using @method, but pretty much only a
single line of description.



What would you all do?


Regards,

Richard Quadling.
-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Implementing optional methods in a concrete class, but calling them from an abstract class.

2010-11-01 Thread Nathan Nobbe
On Mon, Nov 1, 2010 at 9:13 AM, Richard Quadling rquadl...@gmail.comwrote:

 Hi.

 I have an abstract base class (call it genericServiceHandler).

 I have concrete classes (FaxService, EmailService).

 The genericServiceHandler is watching for commands from an external
 source. The commands will always be one of a fixed set, no matter what
 the concrete service is. They are Pause, Continue, Start, Stop,
 Shutdown, PreShutdown.

 The genericServiceHandler has no need to process the commands. It only
 receives them and maybe dispatches them to the concrete class.

 The concrete class doesn't have to implement handlers for all of the
 commands, though, at a minimum, onStart() would be pretty much
 essential.


 My question relates to how should I code this.

 Should the base class have empty protected stubs to allowing the
 concrete class to override them via inheritance?

 Should I use __call() to capture the non-existing methods and use LSB
 to allow the concrete class to get the commands?


 I need to document this (phpdoc) to allow those designing the actual
 services know what to implement.

 The empty stubs certainly seems the easiest as I can block the scope
 to protected and include a full reasoning on when the method will be
 called (not all commands are applicable at all times).

 Using __call() can be documented using @method, but pretty much only a
 single line of description.



 What would you all do?


i would go w/ the stubbed out methods in the base class. if theres nothing
to do for the default implementation just use the 'null' pattern,

function pause() {}

 __call is something of a last resort for me; i think it's best for proxies
or similar and thats about the most its useful for.

-nathan


Re: [PHP] Implementing optional methods in a concrete class, but calling them from an abstract class.

2010-11-01 Thread Richard Quadling
On 1 November 2010 16:27, Nathan Nobbe quickshif...@gmail.com wrote:
 On Mon, Nov 1, 2010 at 9:13 AM, Richard Quadling rquadl...@gmail.com
 wrote:

 Hi.

 I have an abstract base class (call it genericServiceHandler).

 I have concrete classes (FaxService, EmailService).

 The genericServiceHandler is watching for commands from an external
 source. The commands will always be one of a fixed set, no matter what
 the concrete service is. They are Pause, Continue, Start, Stop,
 Shutdown, PreShutdown.

 The genericServiceHandler has no need to process the commands. It only
 receives them and maybe dispatches them to the concrete class.

 The concrete class doesn't have to implement handlers for all of the
 commands, though, at a minimum, onStart() would be pretty much
 essential.


 My question relates to how should I code this.

 Should the base class have empty protected stubs to allowing the
 concrete class to override them via inheritance?

 Should I use __call() to capture the non-existing methods and use LSB
 to allow the concrete class to get the commands?


 I need to document this (phpdoc) to allow those designing the actual
 services know what to implement.

 The empty stubs certainly seems the easiest as I can block the scope
 to protected and include a full reasoning on when the method will be
 called (not all commands are applicable at all times).

 Using __call() can be documented using @method, but pretty much only a
 single line of description.



 What would you all do?

 i would go w/ the stubbed out methods in the base class. if theres nothing
 to do for the default implementation just use the 'null' pattern,
 function pause() {}
  __call is something of a last resort for me; i think it's best for proxies
 or similar and thats about the most its useful for.
 -nathan

That does seem to be the best fit for me.

I can protect and docblock the methods.

Thanks Nathan.

Richard.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Implementing optional methods in a concrete class, but calling them from an abstract class.

2010-11-01 Thread Andrew Ballard
On Mon, Nov 1, 2010 at 11:13 AM, Richard Quadling rquadl...@gmail.com wrote:
 Hi.

 I have an abstract base class (call it genericServiceHandler).

 I have concrete classes (FaxService, EmailService).

 The genericServiceHandler is watching for commands from an external
 source. The commands will always be one of a fixed set, no matter what
 the concrete service is. They are Pause, Continue, Start, Stop,
 Shutdown, PreShutdown.

 The genericServiceHandler has no need to process the commands. It only
 receives them and maybe dispatches them to the concrete class.


Right up to here, it sounded more like an interface than an abstract base class.


 The concrete class doesn't have to implement handlers for all of the
 commands, though, at a minimum, onStart() would be pretty much
 essential.

[snip]

And then it didn't.  :-/


Andrew

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Implementing optional methods in a concrete class, but calling them from an abstract class.

2010-11-01 Thread David Harkness
On Mon, Nov 1, 2010 at 10:42 AM, Andrew Ballard aball...@gmail.com wrote:

 Right up to here, it sounded more like an interface than an abstract base
 class.


I think there's an interface in there *and* a basic (HTTP? RPC?)
implementation that receives and dispatches the messages. I would split
these responsibilities into two separate classes which would allow you to
wire up the services to different dispatchers over time.

But to your original question, Richard, I agree with Nathan. Go with the
solution that is both easy to code and and easy to read, especially given
that the API is quite static.

David