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

Started by
13 comments, last by chadsxe 17 years, 1 month ago
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?
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
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;


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.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
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.
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.
....[size="1"]Brent Gunning
You also need to realize that people commonly use the word "class" or the name of a class when the really mean "an object of the class".
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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.
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.
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.

This topic is closed to new replies.

Advertisement