Class vs Object vs Variable
A class is the formal definition of an object. Just like blueprints can define a building or a recipe can define a cake, a class tells you how to model or construct an object. I do like the cookie cutter analogy for a class. If the details tell you to "bend" the metal a certain way, you end up with a Christmas tree. If the details tell you to bend the edges a different way, you end up with a Star. The class defines how the object will look and what it can do. When you are done defining a class, you know exactly how it will look and act.
An object is the existence of a class. If you have a cookie cutter (as defined by the class details), but no cookie dough into which to press the cookie cutter, you don't have a cookie (an object of the class). An object is created (instantiated) when you take the cookie cutter (i.e., the class definition), press it into the dough (memory), and extract the resulting piece of dough (the object of the class). Now you are free to use the object (i.e., the cookie) as you see fit (e.g., bake it, eat it, put sprinkles on it, coat it with frosting, whatever).
A variable is really nothing more than some bytes in memory that have a name. For example, if you define an integer as:
int myVar;
the operating system (Windows) sets aside four bytes of memory and refers to it as myVar. The exact location of where myVar resides in memory is myVar's lvalue. The data stored in those four bytes of memory is myVar's rvalue. You have the ability to change myVar's rvalue through as assignment, but only the operating system can change it's lvalue.
I hope this helps.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
|