Use OrderedCollection or subclass it?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Use OrderedCollection or subclass it?

Fernando Rodríguez
Hi,

I'm writing a spam filter and have String method that parses it into an
OrderedCollection of SpamTokens. I need to add a method to
OrderedCollection that analizes those SpamTokens and decides if the
whole thing is spam or not.

However, the OrderedCollection method would only make sense if all the
instances in it are SpamTokens. Should I still use the generic
OrderedCollection or create a specific subclass that only accepts
SpamTokens?

I'm afraid this is my C++ haunting me...


Reply | Threaded
Open this post in threaded view
|

Re: Use OrderedCollection or subclass it?

Reinout Heeck-3
Fernando wrote:

> Hi,
>
> I'm writing a spam filter and have String method that parses it into an
> OrderedCollection of SpamTokens. I need to add a method to
> OrderedCollection that analizes those SpamTokens and decides if the
> whole thing is spam or not.
>
> However, the OrderedCollection method would only make sense if all the
> instances in it are SpamTokens. Should I still use the generic
> OrderedCollection or create a specific subclass that only accepts
> SpamTokens?
>
> I'm afraid this is my C++ haunting me...
>


This is a judgment call, both ways are ok.

You could start with 'the simplest thing that could possibly work' (use
OrderedCollection) and only when you decide the code is getting too ugly
  move it into a custom class.

There are some other forces in play of course, for example if this will
be a library that will be reused outside your control you will want to
have a stable API. In such a case it might be desirable to use a
specialized class from the start.


HTH,

Reinout
-------