|
Posted by Richard Levasseur on 08/22/06 15:34
Jerry Stuckle wrote:
> terence.parker@gmail.com wrote:
> > 'Alert' is not a type of 'Parser', but because I want to share some of
> > the functions/variables defined in Parser I decided inheritance was the
> > best way to achieve this. I don't particularly want to re-instantiate
> > Parser inside of Alert, nor do I want to redo things such as MySQL
> > connections.
> >
>
> If Alert is not a type of Parser, then you should not be deriving Alert
> from Parser.
>
Building on what Jerry is saying, it is commonly referred to as 'is a'
and 'has a'/'uses' relationships.
You should be asking yourself:
Is Alert a Parser? => Derive
Does Alert use a Parser or have a Parser within it? => Alert contains
an instance of Parser as a property
Does Alert need to behave like a Parser? => Use an interface
Another way to ask yourself is:
Do I need the polymorphism of overriding the methods?
Do I need direct access to underlying code (when there are protected
vars/methods)?
Does this new class need to interoperate with routines that expect a
normal Parser object?
Judging from only your class names, I'm going to guess that you don't
need to derive Alert from Parser, the logic being Alert probably uses
data that has been parsed, not it does the parsing itself.
Navigation:
[Reply to this message]
|