Thursday, April 16, 2009

Introduction to Object-Oriented Progamming

If you are completely new to programming then there is something you have to understand before you start programming C#. That is the idea of object-oriented programming (OOP). The idea of OOP works something like this. The world is made up of objects. A cat is an object. Your computer is an object. You are an object.

So what does that mean to a programmer? In your applications you break everything that you are trying to model into objects. Say you are trying to write a program that models cars. Think about a car. What are some of things that are common to all cars? Well, cars all have a manufacture like Ford, Buick, Toyota. Cars all have colors. Cars all have a number of gears. Cars can be standards or automatics. These are just a few of the common things about cars. So why is this useful? Well, if you wanted to model a car you need to understand the attributes of cars. Attributes are used to differentiate objects.

Cars also have behaviours. For example you can turn on or off the ignition. You can change gears. You can change speeds. You can steer. Why is that important? When modelling an object you will want the object to perform different actions. These actions are called methods.

So how would you go about implementing this in your programs? You would use what is called a class. A class is used to define the attributes and methods of an object. You can think of a class like a template. When you need a new object you use a class to make the object.

That is a lot to take in so that is all I will be writing about today. Tomorrow I will show you how you would go about creating a class.


-----------------------------
Proud member of Dream.In.Code

No comments:

Post a Comment