Having trouble distinguishing between a "Class" and a "Object"
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?
A class is the definition, an object is the instance of a class, for example:
MyClass is a new type here:
An object is the instance of a class:
Using your code it might look like this:
bankOfScotland and bankoEngland are objects that you have created that are of type Bank.
Hope that clarifies.
Dave
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.
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.
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.
"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.
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".
Quote:Original post by skittleoQuote: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 CoderQuote: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
Popular Topics
Advertisement