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

From: Date: Mon, 01 Nov 2010 16:27:28 +0000
Subject: Re: Implementing optional methods in a concrete class, but calling them from an abstract class.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-309202@lists.php.net to get a copy of this message
On Mon, Nov 1, 2010 at 9:13 AM, Richard Quadling <rquadling@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

« previous php.general (#309202) next »