2 Answers
2

It looks like a template method pattern, but the methods in question are not abstract and the child class is not being forced to implement them. I'd say it's just a common use of inheritance or maybe a borderline template method pattern.

I'd rather implement such things via events/delegates/callbacks, though. It is much clearer then what you can hook up to and you can't accidentally override necessary behaviour. It's also more flexible.

@GSto

Here's an example of using callbacks with PHP. It's not as elegant as in other languages with native event support (like C# offers for example), but it's flexible and you can register such callbacks in the constructor of a child class for example. This website here told me how to implement callbacks in PHP, the heart of it is the call_user_func function of PHP. This can register as many handlers as you like and anything with a reference to the object can register handlers.

interesting, do you have an example of how you would handle this in the manner you described?
–
GStoSep 1 '11 at 15:19

2

AFAIK this is template method pattern (or a variation of it), and when the Wikipedia article talks about "abstract methods", IMHO it does not mean necessarily methods which force the subclass to implement them, but also virtual methods which may have an empty (or even a non-empty) default implementation.
–
Doc BrownSep 1 '11 at 15:38

@Doc Brown: You can call it a variation. I think it's just close enough to call it template method, but it isn't a classical template method pattern and thus it becomes classical method overriding, basically just usage of inheritance. Also, see wikipedia's definition of abstract method, they do mean it in an OOP sense.
–
FalconSep 1 '11 at 15:57

@Falcon: well, I have the GOF book here in my hand and the description of the template method pattern does not insist the virtual methods have to be pure virtual / abstract. In fact, hooks with empty default implementation are explicitly mentioned. I gave you +1, either.
–
Doc BrownSep 1 '11 at 16:26

This looks like a pretty standard case of any inheritance-based model, depending on how you use it. It's pretty common to put any implementation specific code in virtual functions in an abstract parent, and to implement them in a child class.

This is literally the exemplar case in c++; it looks like you're using PHP, here, and this is definitely the preferred method. Much easier to follow than using callbacks. If you're using this in an MVC framework (Or building one) you might want to prepend a '_' to the setup utility call.