class inheritance

  • Thread starter Thread starter VM
  • Start date Start date
V

VM

I'm working on four classes where each method in the class (about 5 methods
per class: approx. 20 methods have to Open() and Close()) has to execute the
Open and Close processes. Should I create one class that includes only these
two methods and inherit all four classes from this main class? Or is this
not worth the additional trouble?

Also, is the relationship between a base class and an inherited class the
same as a parent-child class (ie. are they the same thing?)?

Thanks.
 
You should only derive classes if there is a true relationship between the
classes. Just because they all use an Open and Close method may not mean
they are related. That will be something that you will have to determine.
If the classes are not related, the methods like the Open and Close might
best be part of a helper class but don't make inheritance decisions based on
the number of times a method is called.
 
Thanks for the info.

They are somewhat related. These four methods just do several dll function
calls and in order for me to execute these functions, I need to "open" and
"close" the dll. That's why I was thinking of making a class out of them.
And if the open and close function parameters change (although chances are
it'll never happen), I'd have to go to each method and do the necessary
changes.

The real reason I asked is because I want to learn how to develop correct
OOP designs.
 
You may also want to look into interfaces. It sounds like you may have a
good candidate.
 
Back
Top