Lost Password?

Go Back   CodeCall Programming Forum > Software Development > General Programming

General Programming Non language specific, Assembly, Linux/Unix, Mac and anything not covered in other topics. Talk about Programming Theory here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-20-2006, 11:03 PM
Nightracer's Avatar   
Nightracer Nightracer is offline
Programmer
 
Join Date: Jun 2006
Posts: 130
Rep Power: 9
Nightracer is on a distinguished road
Default Objects

Quote:
an object is an individual unit which is used as the basic building block of programs.
These objects act on each other, as opposed to a traditional view in which a program may be seen as a collection of functions, or simply as a list of instructions to the computer. Each object is capable of receiving messages, processing data, and sending messages to other objects.
Each object can be viewed as an independent little machine or actor with a distinct role or responsibility.
So I think we all know what objects are.
But how do you determine what to make an object? I often make the mistake of having TOO many objects.
How do you decide what should be an object?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 06-21-2006, 03:44 PM
dirkfirst dirkfirst is offline
Programming Professional
 
Join Date: May 2006
Posts: 338
Rep Power: 11
dirkfirst is on a distinguished road
Default

Good question......... I don't think there is a correct way to determine what to make an object. I would make anything an object that you plan on using more than once such as a wrapper.

Objects are classes, correct?
__________________
DirkFirst
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-21-2006, 04:03 PM
TkTech TkTech is offline
 
Join Date: Jun 2006
Posts: 896
Last Blog:
Having trouble with yo...
Rep Power: 20
TkTech is on a distinguished road
Send a message via MSN to TkTech
Default

Quote:
Objects are classes, correct?
Right.

Lol to many objects? Ive made entire programs all in class's, ie the entire content of main on a mac space invaders game i made ( for fun ) was:

Code:
void main( void )
{
WORLD world;
WindowPtr win;
int x=0,y=30;

world.init( &win );
for( int x=0;x<20;x++)
world.en_new( world.enemy , x+10 , y );
world.sp_spawn();

do
{
world.setworld( world.offscrn );
world.en_move();
world.en_update();
world.sp_checkkey();
world.setworld( world.window );
world.sp_draw();
world.en_draw();
world.speed();
}while(1);

}
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-21-2006, 07:26 PM
brackett brackett is offline
Programmer
 
Join Date: May 2006
Posts: 193
Rep Power: 10
brackett is on a distinguished road
Default RE: Objects

Quote:
Originally Posted by Nightracer
So I think we all know what objects are.
But how do you determine what to make an object? I often make the mistake of having TOO many objects.
How do you decide what should be an object?
There's a lot of different methods to designing a system: CRC cards, UML diagrams, user stories, etc. For the most part, your classes (I use "class" when talking about code, "object" when talking about a program - a class is a definition of an object) will be modeled after reality - whatever reality your system has to deal with.

A simple method to get you started is to describe your system, and then pick out the nouns you used to describe your problem domain. Those nouns are usually good candidates for a class.

Though I'd say it's difficult, it's not impossible to have "too many classes". But really, it's more likely that you (like I have a tendency to do) are complicating the subject matter. In your complex modeling of the reality, you've identified a lot more players than are actually needed to perform the job. So, your problem isn't really that you have too many classes, it's that your model is too complex.

In general (excepting the case above - which is a modeling problem), the more classes the better. By having more classes, each class can have a well defined role (the Single Responsiblity Principle) and can be understood easily. By taking for granted that a class does its responsibility correctly, it's easier to understand a small part of the system without having to grasp all of the the code at once.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-24-2006, 09:54 PM
Nightracer's Avatar   
Nightracer Nightracer is offline
Programmer
 
Join Date: Jun 2006
Posts: 130
Rep Power: 9
Nightracer is on a distinguished road
Default

Quote:
Originally Posted by dirkfirst
Good question......... I don't think there is a correct way to determine what to make an object. I would make anything an object that you plan on using more than once such as a wrapper.

Objects are classes, correct?
No, an object is an instance of a class..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 07-25-2006, 05:41 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,047
Last Blog:
NaNoWriMo Summary
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

I'll give you an example: Let's say you want to make a chess game. Classes that come to mind for me are:
Game
Board
Piece (inherit down to individual types)
Turn
Player
History

Objects of these classes will interact for things such as attacks, pieces knowing how they move and where they are, checking for stalemate by repetition, etc. Think about what objects exist in the problem, and you get your classes.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-26-2006, 01:23 AM
brackett brackett is offline
Programmer
 
Join Date: May 2006
Posts: 193
Rep Power: 10
brackett is on a distinguished road
Default

One classic way to define your classes would be to write out your different scenarios, and then look at the nouns. Those are good candidates for classes. The verbs are good candidates for methods.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-26-2006, 10:02 PM
Nightracer's Avatar   
Nightracer Nightracer is offline
Programmer
 
Join Date: Jun 2006
Posts: 130
Rep Power: 9
Nightracer is on a distinguished road
Default

Wingedpanther again you post a great response!
Love the examples you give, it really clears things up as far as explaining goes!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-28-2006, 08:02 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,047
Last Blog:
NaNoWriMo Summary
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

You should see me when I teach math!
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
G++ Error: cannot pass objects of non-POD type Ronin C and C++ 4 10-01-2007 04:35 AM
[Query]TreeMap and TreeSet objects. How to use? Musashibo Java Help 0 06-05-2007 09:18 AM
Objects.. idgeitman Java Help 3 04-22-2007 10:42 PM
Java:Tutorial - Adding more objects to your window John Java Tutorials 0 01-11-2007 02:09 PM
Classes, Methods, and Objects Sionofdarkness Java Help 6 08-21-2006 12:55 PM


All times are GMT -5. The time now is 12:08 AM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
LogicKills ........ 20.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 67%

Ads