Object-Oriented Programming
Classes and Objects
A class is the type or blueprint of an object while an object is an instance of a class.
An analogy: Wizard and Barbarian are two classes of hero. Gandalf and Harry Potter are both instances (objects of type) Wizard. Meanwhile Conan and Thundaar are both instances of Barbarian. So when we say "Gandalf the Wizard", Gandalf is an object that is an instance of class Wizard.
In object oriented programming we write classes that define how a type of thing is going to work and then later on we create one or more objects of a class to accomplish a particular goal. You might write a single Orc class to define how an Orc behaves and then you might create 20 Orc objects to give the hero something to fight!
References
We store objects in variables called references. The variable is not itself the object, but rather it points to or references the actual object which is floating around off in the computer's memory somewhere. Objects are assign by-reference which means that when you say "x = y", you didn't make a copy of the data but rather set x to reference the same object that y is referencing.
References to objects are like URL's to web sites. If I write "plasmaworks.com" down on a piece of paper, that piece of paper is not itself the website, it's a reference to where I can find the website. If I show you my piece of paper and you write down "plasmaworks.com" on your own piece of paper, you didn't just make a copy of the website (there's not two websites now!) - you just copied the reference to it.
- Login to post comments
