Classes and Objects (Visual Basic .NET)
November 12th 2006 08:00
I’m writing my Visual Basic .NET exam in a few days, and my one friend keeps on asking me what the purpose of a class is – so here goes my conceptual and brief explanation of classes (and please, correct me if I’m wrong.)
Say that you are a programmer, and you want to program virtual persons (something like Sims.) Now there’s two ways you can go about doing this:
1) You can program each and every one of them from scratch: limb by limb, toe by toe, hair by hair.
2) You can first program a generic mold for a person, and then just modify the mold each time you want a different person.
The mold in option 2 is exactly what a class is.
First you ask yourself: What does all persons have? That’s easy: A name, weight, length, head, two arms, two legs, and a torso. This attributes is essential for any person mold (and this attributes are known as the properties of your class.)
But everyone is unique, right? This means that we need a way to make each person with a different name, weight, length, and so on. We need a way to tailor our mold to match the specifications of the specific person we are programming. Imagine that we do this by using a control panel that allows you change the shape of the head, or length of the arms inside the mold for example. This ability to change your mold is the most important aspect of classes, and is known as the methods of the class.
Look at this example of a class: (Note that the class consists of properties and methods.)
Now we actually want to start programming people. The actual person that comes out of the mold is called an object.
Let’s program three people: Jojo, Bob and Sydney. We will use the dot as a way to indicate which method is applied to which property, i.e Name.Change Name = “Emile.” This means that we used the Change Name method to change the Name property to “Emile.”
The specs for each of our three persons will look something like this:
See the beauty of classes yet? We used one mold to program three very unique persons, using only their methods to distinguish them.
So what is a class? A class is a grouping of properties and methods. It allows you to change these properties via methods. Imagine the power that classes puts at your fingertips: you can now add more distinguishing methods to the class – for example, you can program your persons so that they have the ability to run, jump, kick and shout. All three of the persons will do these actions very differently.
Classes sure make programming a whole lot easier.
Say that you are a programmer, and you want to program virtual persons (something like Sims.) Now there’s two ways you can go about doing this:
1) You can program each and every one of them from scratch: limb by limb, toe by toe, hair by hair.
2) You can first program a generic mold for a person, and then just modify the mold each time you want a different person.
The mold in option 2 is exactly what a class is.
First you ask yourself: What does all persons have? That’s easy: A name, weight, length, head, two arms, two legs, and a torso. This attributes is essential for any person mold (and this attributes are known as the properties of your class.)
But everyone is unique, right? This means that we need a way to make each person with a different name, weight, length, and so on. We need a way to tailor our mold to match the specifications of the specific person we are programming. Imagine that we do this by using a control panel that allows you change the shape of the head, or length of the arms inside the mold for example. This ability to change your mold is the most important aspect of classes, and is known as the methods of the class.
Look at this example of a class: (Note that the class consists of properties and methods.)
Now we actually want to start programming people. The actual person that comes out of the mold is called an object.
Let’s program three people: Jojo, Bob and Sydney. We will use the dot as a way to indicate which method is applied to which property, i.e Name.Change Name = “Emile.” This means that we used the Change Name method to change the Name property to “Emile.”
The specs for each of our three persons will look something like this:
See the beauty of classes yet? We used one mold to program three very unique persons, using only their methods to distinguish them.
So what is a class? A class is a grouping of properties and methods. It allows you to change these properties via methods. Imagine the power that classes puts at your fingertips: you can now add more distinguishing methods to the class – for example, you can program your persons so that they have the ability to run, jump, kick and shout. All three of the persons will do these actions very differently.
Classes sure make programming a whole lot easier.
| 303 |
| Vote |
Subscribe to this blog







Comment by Ahmed
Video Gamer Kids
Little Green Foosballs
PolyKicks
Havne't touched VB in eons though, like eons eons, uni recquires c and Java (also c but thats not OOP based sadly)... I think classes work best in java, easiest to manage and all...
Comment by Jessicca
Learning Something Everyday
Malaysia Found
Yes, parent classes are generic mold objects (like you said) for re-creation objects or for other classes to inherit this particular object's properties.
Though I haven't truly touched VB.NET, but creating COM objects is relatively the same in VB. The difference is that VB.NET is a little more advance and more C based when it was introduced in the beginning.
Comment by Chantal
Maybe it was "The Sims" mention that got me... I love that game!!