On Dec 25, 11:53 pm, "JoeC" <enki...@yahoo.comwrote:
andrewmcdonagh wrote:
On Dec 25, 5:18 pm, "JoeC" <enki...@yahoo.comwrote:
I have a question about designing objects and programming. What is the
best way to design objects? Create objects debug them and later if you
need some new features just use inhereitance. Often times when I
program, I will create objects for a specific purpose for a program and
if I need to add to it I just add the code.
And there is nothing much wrong with 'just adding the 'behaviour' to an
existing class.
Unless.....
That class is used by other teams, is an API, is used lotsof times
throughout your large code base(i.e. causing a massive recompile),
etc....
What you might want to try, is creating a new Class instead of just
adding to an existing one - this usually results in a very flexible
design.
I would also favour Delegation over Inheritance.
Delegation is a Dynamic relationship between 2 objects, whereas
Inheritance is a static compile time relationship. Static
relationships tend to make designs more inflexible.
my 2c
HTH
AndrewThanks, I write games and stuff working by my self. I have expanded
some classes if I use them from one project to the next. The reason
why I ask is that I find good technique and style actually helps me
write better programs. When I write a program I will create some class
as I move further on in my program I realize that I need some accessor
or display graphic in a slightly different way. I was working on my
game and for a while I was trying to draw a marker box. The way I
originally wrote the code is the pixels are converted to spaces to be
displayed. But what I was trying to do was display the box with un
converted pixels. I was wondering if simple expanisons of classes was
good or bad design. The draw back would be this whole mess of
confusing small files with each add on.
I am intersted in programming and teaching myself. Lerning syntax is
pretty easy I can look up most things in a book but when I write larger
programs (my current project has 30 separate fiels and I don't know how
many lines of code) but technique and orginization is just as important
as writing syntax that works. I have been trying to improve my
programming techniques and this allows me to write better programs.
It sounds like you have stumbled onto a technique known as 'evolving
design' instead of the typical 'upfront design'.
This can be a hugely powerful technique, if used correctly.
It can also lead to a mess of a design ;-)
Have you done any reading on TestDrivenDevelopment ?
It sounds like it could suit your style well.
Ignore the 'Test' part of the name, its a design technique, not a test
technique. It allows us to start with a tiny design and watch it
evolve into the one we need for the application. Its the opposite of
creating 'reusable' frameworks'.
The 'Test' part of the name, comes from the first step of each design
cycle: Write a Failing Unit test'
This (failing to pass) test drives us to write Just Enough Code to make
it Pass.
Then we 'Refactor' the current design to remove Duplication (either
code if its the same or behaviour if the code is different but performs
the same job)
Next, we go back to writing our second (failing) Unit Test, rinse and
repeat.
The beauty of having numerous small passing unit tests, means we can
SAFELY refactor or evolve our design. Any problems we cause by
refactoring or evolving are caught by our unit tests.
There's whole books on this subject, so instead of writing it out
here...here's some links...
http://www.testdriven.com/modules/news/ http://cppunit.sourceforge.net/cppunit-wiki/FrontPage http://tut-framework.sourceforge.net/howto/
google ;-)
Regards
Andrew