Read + Write + Report
Home | Start a blog | About Orble | FAQ | Blogs | Writers | My Orble | Login

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.

304
Vote


   

   

   


Comments
3 Comments. [ Add A Comment ]

Comment by Ahmed

November 12th 2006 10:29
gotta love classes. OOP's greatest asset to programming in general no doubt.


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

November 13th 2006 08:26
Great post about the definition of classes, Emile. ^_^

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

December 4th 2006 23:18
Wow!! I am like the least technical person ever and I found that totally interesting!!

Maybe it was "The Sims" mention that got me... I love that game!!

Add A Comment

To create a fully formatted comment please click here.


CLICK HERE TO LOGIN | CLICK HERE TO REGISTER

Name or Orble Tag
Home Page (optional)
Comments
Bold Italic Underline Strikethrough Separator Left Center Right Separator Quote Insert Link Insert Email
Notify me of replies
Notify extra people about this comment
Is this a private comment?
List the Email Addresses or Orble Tags of the people you would like to be notified about this comment


One per line max of 30

List the Email Addresses or Orble Tags of the people you would like to be notified about this private comment thread. Only the people in this list will be able to see or reply to your comment.


One per line max of 30

Your Name
(for the email going out to the above list, it can be different to your Orble Tag)
Your Email Address
(optional)
(required for reply notification)
Submit
More Posts
5 Posts
5 Posts dating from November 2006
Email Subscription
Receive e-mail notifications of new posts on this blog:
0
Moderated by Emile
Copyright © 2006 2007 2008 On Topic Media PTY LTD. All Rights Reserved. Design by Vimu.com.
On Topic Media ZPages: Sydney |  Melbourne |  Brisbane |  London |  Birmingham |  Leeds     [ Advertise ] [ Contact Us ] [ Privacy Policy ]