473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Object Design Question

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
6 2108


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

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


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
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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ggg | last post by:
I'm looking for a complete project/application done with heavy use of of object-oriented programming & design. Preferably something well documented and/or commented so that I can pick it apart...
3
by: andy2O | last post by:
Hello comp.lang.py, Can you help me with ideas for the following (somewhat newbie) OO design question in Python? Note, I'm using psuedo-code, not actual Python for the examples! Background:...
6
by: blueblueblue2005 | last post by:
here is a friend function of Class Array, which has two private data member: int size, int *ptr // Array's public member function to return size int getSize() const { return size; } friend...
22
by: ypjofficial | last post by:
Is there any possibility of invoking the member functions of a class without creating an object (or even a pointer to ) of that class. eg. #include <iostream.h> class test { public: void...
4
by: Carl J. Van Arsdall | last post by:
It seems the more I come to learn about Python as a langauge and the way its used I've come across several discussions where people discuss how to do things using an OO model and then how to design...
17
by: Divick | last post by:
Hi, I am designing an API and the problem that I have is more of a design issue. In my API say I have a class A and B, as shown below class A{ public: void doSomethingWithB( B * b) { //do...
11
by: John A Grandy | last post by:
I'm in a vigorous debate at my work regarding objects assuming knowledge of the type their containing object. This debate pertains specifically to ASP.NET, but I have decided to post in the C#...
0
by: =?Utf-8?B?SmVhbi1GcmFuY29pcyBCcmV0b24=?= | last post by:
"siddharthkhare@hotmail.com" wrote: The context is important in this kind of design concern : I assume there's a lot of user and that application will evolve to add richer functionality. My...
3
by: H. S. Lahman | last post by:
Responding to siddharthkhare... Ignore Topmind and frebe. They are anti-OO P/R guys. Let's not confuse things with specific 3GL syntax. At the OOA/D level the model looks like: | 1
7
by: joproulx | last post by:
Hi, I was wondering if there was a way with Reflection to find dynamically if an object was referencing indirectly another object. A simple example would be: Object1 | --Object2 |
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.