Create many similar classes, or just one

Posted by soandos on Programmers See other posts from Programmers or by soandos
Published on 2012-05-31T04:50:21Z Indexed on 2012/05/31 10:49 UTC
Read the original article Hit count: 193

Filed under:
|

The goal is to create an application that has objects that can represent some operations (add, subtract, etc).

All of those objects will have common functions and members, and thus will either implement an interface or inherit from an abstract class (Which would be better practice, this will be in C# if that matters?).

As far as I can see, there are two different ways of organizing all of these classes.

  1. I could create an addition class, a subtraction class, etc. This has the upside of being highly modular but the difference between classes is so minimal.
  2. I could create one class, and have a member that will say what type of operation is being represented. This means lots of switch statements, and losing some modularity, in addition to being harder to maintain.

Which is is better practice? Is there a better way of doing that is not listed above? If it matters, the list of functions that should be supported is long.

© Programmers or respective owner

Related posts about design

Related posts about design-patterns