473,598 Members | 3,276 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2129


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 TestDrivenDevel opment ?

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 TestDrivenDevel opment ?

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.GetFr ame(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 TestDrivenDevel opment ?
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
AndrewInterstin g 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.GetFr ame(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
3463
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 and learn how/why they designed it they way they did. Any suggestions?
3
1484
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: ----------- I need to represent a small variety of mathematical constructs symbolically using Python classes.
6
4106
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 istream &operator>>(istream &in, Array &a) { for(int i=0; i<a.size; i++) // do something
22
2741
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 fun() {
4
1790
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 software in a more "Pythonic" way. My question is, should we as python developers be trying to write code that follows more of a python standard or should we try to spend our efforts to stick to a more traditional OO model? For example, in...
17
2583
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 something with b //possibly store in a list
11
1348
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# forum because this is where most of the OO gurus hang out, and I view this as a fundamental issue of OO design. In ASP.NET, objects of type WebForm and UserControl have an intrinsic Page property which refers to their containing Page.
0
1142
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 first concern would be to separate the business logic code from data contener : the new code would look like that : LineItemBusinessComponent.Delete(LineItemBusinessEntity) Exposing CRUD component isn't the best thing to do because your presentation...
3
157
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
1688
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
7992
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8398
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8051
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3898
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3940
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2414
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.