By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,133 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,133 IT Pros & Developers. It's quick & easy.

Object Design Question

P: n/a
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.

Dec 25 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a


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

Andrew

Dec 25 '06 #2

P: n/a

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

Andrew
Thanks, 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.

Dec 25 '06 #3

P: n/a


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

Dec 26 '06 #4

P: n/a
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
Intersting I thougnt test driven design was using a bunch of assert
commands like this program:

void test1(){
// 2 frames no spare or strike
score p1;
p1.ball( 5 );
p1.ball( 3 );
assert( p1.Total() == 8 );
assert(p1.GetFrame(0) == 8);
p1.ball( 4 );
p1.ball( 4 );
assert( p1.Total() == 16 );
}

Still what you describe is what I do. I have a project and I know what
I want to do and I do the best to anticipate what my objects will need
to do but at times, I need some extra book or some accessor that it a
bit different. When I put in things I think I will need I end up not
using them. I can see how a vector or other standard library would be
standardized but a Unit or map manager for my wargame is not a general
concept it has to do specific things and when I design my object I have
an idea what I want it to do but when I want to stack my units with an
ofset it takes some function I didn't not anticipate.

I can see how generalized programming is useful. In my game I have
base map engine but then expanded it to include a graphic map and to
handle the graphics or I wrote a simple graphic class I have used in
now three programs with little modification if any.

Dec 26 '06 #5

P: n/a


On Dec 26, 12:40 am, "JoeC" <enki...@yahoo.comwrote:
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
AndrewIntersting I thougnt test driven design was using a bunch of assert
commands like this program:

void test1(){
// 2 frames no spare or strike
score p1;
p1.ball( 5 );
p1.ball( 3 );
assert( p1.Total() == 8 );
assert(p1.GetFrame(0) == 8);
p1.ball( 4 );
p1.ball( 4 );
assert( p1.Total() == 16 );

}Still what you describe is what I do. I have a project and I know what
I want to do and I do the best to anticipate what my objects will need
to do but at times, I need some extra book or some accessor that it a
bit different. When I put in things I think I will need I end up not
using them. I can see how a vector or other standard library would be
standardized but a Unit or map manager for my wargame is not a general
concept it has to do specific things and when I design my object I have
an idea what I want it to do but when I want to stack my units with an
ofset it takes some function I didn't not anticipate.

I can see how generalized programming is useful. In my game I have
base map engine but then expanded it to include a graphic map and to
handle the graphics or I wrote a simple graphic class I have used in
now three programs with little modification if any.
With TDD, the generalisation you look forward in your own code's design
emerges during repeating 3 steps. Your Maps might all extend from a
common Map base class, but to begin with - you only start out with one
Map class. When you want a new Map, you'd write a test for it and make
it pass, by deriving from the first map. Then the most important Step -
refactor. Here you may decide that its better to not extend the first
Map class, but instead to extend a common base class. So perform the
'Pull up into Base class' refactoring upon your first map.

Then re-run your test to prove you haven't broken anything.

Then change your new Map to extend from the Base class instead.

rinse, repeat....

Dec 26 '06 #6

P: n/a
With TDD, the generalisation you look forward in your own code's design
emerges during repeating 3 steps. Your Maps might all extend from a
common Map base class, but to begin with - you only start out with one
Map class. When you want a new Map, you'd write a test for it and make
it pass, by deriving from the first map. Then the most important Step -
refactor. Here you may decide that its better to not extend the first
Map class, but instead to extend a common base class. So perform the
'Pull up into Base class' refactoring upon your first map.

Then re-run your test to prove you haven't broken anything.

Then change your new Map to extend from the Base class instead.

rinse, repeat....
That is pretty much what I do the not breaking anything is the hard
part. I am almost done with my game I just have to write the combat
resolution part. I am pretty sure I can just cut and paste in the
system from my last project with some minor changes.

If your intersted I can send a copy of the game I wrote. It is in
win32 but it is lots of work and I would like to share it to get an
idea of my skill level.

Dec 26 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.