Jump to content

Why use object in c++

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
mindblaster

mindblaster

    Newbie

  • Members
  • PipPip
  • 17 posts
Hi!

I am come back with my Problem...:confused:

Now,
I want to know that WHY use object in program. is program incomplete without using the Object/Classes
2) How many times I create new Object?

Just Suppose I want to Create Phone Book in C++. Now, How many objects/classes will be made? Is Phone Book Completed in one Object.

Regards.:p
Posted Image
Join SuperDiscountShop.com at Facebook.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You don't need to use objects at all, and sometimes shouldn't. Even with something as simple as a phone book program, you could easily have one, two, or multiple classes. You could also easily start using subclasses, depending on how complicated you want to make it.

Start by asking yourself a different question: what are you trying to do, and how can you organize the information you will need to keep track of?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Mathematix

Mathematix

    Programmer

  • Members
  • PipPipPipPip
  • 112 posts
We use objects/classes to group the attributes of a perceived entity together in one 'package' that provides easy way of accessing those attributes and ensuring that all appropriate changes are propagated through the object/class.

Take a character in a video games, for example, you will may have an object for the head with attributes and methods for eye animations, facial expressions, etc. Likewise for arms, legs... all encompassed in one object called something like 'Character'. If the character's mood changes, this change in mood might be reflected with a frown, then changes associated with the frown might be propagated through the 'character object' to alter their posture accordingly.

Doing this without class objects would be a very big pain. :)