RE: OO Design Tradeoffs Question
Here's the question:
Given the above, I could either have a Virtual Line class and derive a
TitleLine, LableLine, and DataLine.
Or
I could just build in attributes, such as the font used to draw, and line
alignment into the Line class and avoid inheritance altogether.
My guess is that if I can avoid inheritance (reduce complexity) that is the
way to go unless there is a case for using it (later maintenance or
expansion).
What questions should I ask myself? The one benefit to the use of
inheritance is that I would avoid having to tell each line which kind it is
by setting its attributes, so it would be easier to use and faster.
Thanks for any thoughts to help me learn how to decide these kinds of
questions.
It depends.
For small scale projects like these, you have to ask yourself: is it worth
all of this?
for small things I sometimes don't bother to use inheritance, polymorphism
etc because implementing all of that and testing it takes a lot of time,
which is sometimes not worth it.
For larger projects it is worth it, and it can save you gianormous amounts
of time and problems, should requirements or design change during the project
lifetime.
If you are writing a small use-once tool, there is no point.
In your case, I think having a virtual line class is a good decision because
it allows you to extend your project later on, and it allows you to have as
little code duplication as possible.
Your Draw function should at least take 1 parameter which is the settings
structure that determines how the screen (font etc) should look like etc.
--
Kind regards,
Bruno.
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"