Jump to content
  • Advertisement
Sign in to follow this  

Having trouble distinguishing between a "Class" and a "Object"

This topic is 4082 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

O.k....so in my ever ending studies I am now trying to further my knowledge of true Object-Orented design and low and behold I can't even distinguish a "Class" from a "Object". So for example lets use oh I don't know a Bank to try and give examples. So... A Class of a bank could be : Vault And a Object of a Vault could be : Currency Does this sound correct?

Share this post


Link to post
Share on other sites
Advertisement
A class is the definition, an object is the instance of a class, for example:

MyClass is a new type here:

class MyClass
{

};

An object is the instance of a class:

MyClass myObjectOfTypeMyClass;


Using your code it might look like this:

class Bank
{
};


Bank bankOfScotland;
Bank bankOfEngland;

bankOfScotland and bankoEngland are objects that you have created that are of type Bank.

Hope that clarifies.

Dave

Share this post


Link to post
Share on other sites
A class is a data structure, an Object could mean an intance of a class. For example:


class Foo
{
//some code
};

// declear an intance of the class Foo
//"bar" is an object of the class Foo.
Foo bar;




Share this post


Link to post
Share on other sites
Imagine a building.

Every building has a set of blueprints and schematics. They have all the details about how to build the building and how things are laid out inside the building. Those blueprints are not the actual buildings, of course. They just describe them.

Classes are blueprints. Objects are buildings.

Share this post


Link to post
Share on other sites
A simpler example:

"Husky", "Beagle", and "Doberman" are classes. They represent a general type of dog.

"Rover", "Fido", and "Rex" are objects. The represent a particular individual dog, that belongs to one of the types of dog.

Share this post


Link to post
Share on other sites
Quote:
Original post by gharen2
A simpler example:

"Husky", "Beagle", and "Doberman" are classes. They represent a general type of dog.

"Rover", "Fido", and "Rex" are objects. The represent a particular individual dog, that belongs to one of the types of dog.


And to that end Dog would be the abstract base class.

Share this post


Link to post
Share on other sites
Quote:
Original post by skittleo
Quote:
Original post by gharen2
A simpler example:

"Husky", "Beagle", and "Doberman" are classes. They represent a general type of dog.

"Rover", "Fido", and "Rex" are objects. The represent a particular individual dog, that belongs to one of the types of dog.


And to that end Dog would be the abstract base class.


Clearly dog subclasses from "Animal"! (Or "Mammal"?).

Dog can also be an aggregation of various physical and qualitative components, which is better.

Share this post


Link to post
Share on other sites
Quote:
Original post by JohnBolton
You also need to realize that people commonly use the word "class" when the really mean "an object of the class".


Yes, I was looking up random numbers in C# today, when I came across this beauty:


Random RandomClass = new Random();



RandomClass is an instance of the Random Class, but it is not a class. "Random" on the other hand, is the class.

Share this post


Link to post
Share on other sites
Quote:
Original post by Cowboy Coder
Quote:
Original post by JohnBolton
You also need to realize that people commonly use the word "class" when the really mean "an object of the class".


Yes, I was looking up random numbers in C# today, when I came across this beauty:

*** Source Snippet Removed ***

RandomClass is an instance of the Random Class, but it is not a class. "Random" on the other hand, is the class.


Wow, what a horrible variable name. x.x

I personally have no problem saying "a Random" as shorthand for "a Random instance" or "an instance of the Random class" (instance here is a synonym for object; the emphasis is shifted away from the thing being an object and towards the class of which it is an object), but I am careful to avoid using the word "class" explicitly to mean "an object of the class", and correct people for this when their usage is particularly confusing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!