|
Posted by ZeldorBlat on 11/23/05 19:11
>But although that's working... it doesn't seem to be really OO :p
Sure it is. OO is just as much aggregation and composition as it is
inheritance. In fact, inheritance limits you in that you can't change
the inheritance at runtime (well, in PHP you can, but OO purists would
have a heart attack). You can modify the composition, however.
In your case, you could mimic your "uses" idea with inheritance. For
instance, you could have validate extend reporting and have sentry
extend validate. But you also need to consider if this makes sense.
Is sentry really a more specific instance of validate? Is validate
really a more specific instance of report? I think the answer is no.
You probably want to use validate with things other than reports.
Based on your example, I think you could probably make validate() a
static method and pass it a report object as a parameter. Or better
yet, create an interface (or abstract class) called "Validatable" or
something. This interface should define all the methods you might need
to validate something (such as getContent(), getEmail(), or
setError()). The report class can then implement/extend Validatable.
Then, inside your validate() method, check that the parameter is an
instance of Validatable and do what you need to do. This way, you can
make anything validatable (an email address, form input, etc.) and just
pass it in.
[Back to original message]
|