Jump to content
shoneill

OOP design parttern name required

Recommended Posts

I was just thinking of a method to achieve something at work when I thought of an idea which almost certainly has a formal name in OOP. Since you guys are generally better at the formal side of things than me I thought I'd pop out a question.

If I have an architecture where I have a multitude (>1) classes which could concievably be used to process a certain input data (format the same but contents different) I don't want to limit my expandability by hard-coding which class handles which data. If I then incorporate a method into the classes to tell me how well they can deal with the data and then choose the best fit, what would I call this approach?

For example: I have a control reference. I have a class to handle digital controls and I have a class to handle Strings. If All I have as an input is "Control" I send this to a function of the objects of my different classes and they tell me if (and how well) they can handle the specific object being passed - taking care of their own up-casting and down-casting as required.)

Shane

Share this post


Link to post
Share on other sites

If I have an architecture where I have a multitude (>1) classes which could concievably be used to process a certain input data (format the same but contents different) I don't want to limit my expandability by hard-coding which class handles which data. If I then incorporate a method into the classes to tell me how well they can deal with the data and then choose the best fit, what would I call this approach?

We do exactly the same thing with one of our applications we've written, each object knows how to manipulate its data by virtue of its class, but the user of the object only cares that its some instance of a base class that can be operated on (it's in fact a base class wire that gets passed around) . However since myself and the other person I work with are both chemists by trade, neither of us know the "proper" name for what we're working on either. To me it's always just been an application of OOP-based polymorphism.

Share this post


Link to post
Share on other sites

If you want to call the same method on the data, but you want the behavior to be different based on the type (i.e., you have a different algorithm for each), this suggests the use of the Strategy Pattern. Check out the first chapter of Head First Design Patterns.

Share this post


Link to post
Share on other sites

If you want to call the same method on the data, but you want the behavior to be different based on the type (i.e., you have a different algorithm for each), this suggests the use of the Strategy Pattern. Check out the first chapter of Head First Design Patterns.

Cheers Paul. I must order that book.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.