Object Oriented Concepts: Part 1

General Development Concepts

Part one of a series of articles detailing the finer points of OO Programming.

Date : 2006-04-14
Object Oriented Concepts

In the next few weeks I will be addressing the core concepts of Object Oriented (OO) Programming from the basics of what an object is to the deeper details of the Inheritance, Interface, and implementation of these concepts in real-world applications.

We will be going over these concepts through a series of articles that focus solely on each individual piece of OO methodology in an attempt to explain to those new to the concept the basic ideas and perhaps to add to the seasoned OO programmer some finer points that they may have overlooked in their previous efforts.

Lesson 1: Objects

Objects are the foundation of Object Oriented (Here-after referred to as OO) Methodology and can easily be likened to objects in real life.

Take for instance a simple table lamp. It can be either on or off (its state) and is able to give off light (its behavior). A car could be likened to an OO object as well having states such as color, style, etc and behavior such as acceleration, braking, or changing gears.

Just like these real world objects, OO objects have both a state and a behavior associated with them. The state of a software object is represented by variables (integer, bool, string, etc) and the behavior of the object is represented through methods which are simply functions or procedures within the object.

So simply stated, an object is a composite of variables and methods.

To illustrate how these variables and methods work together in an object we can use our previous example of a lamp. The lamp itself has attributes which can be modeled as variables such as its ability to be on or off - a boolean operation. Further a method could be defined to describe what happens given a particular state. If the light is on then the method for 'showing light' would be used and if the light was off then the method for 'show darkness' might be kicked off.

Everything that the object knows (its state) and can do (its methods) is wrapped up within the object. The variables intrinsic to the object are formally known as instance variables because they contain the state for a particular object. This is referred to as an instance in OO terminology. Additionally, the methods used in an object are referred to as instance methods because they can inspect or change the state of a particular instance.

Encapsulation is a term that is often heard when speaking of objects because the variables that are a part of an object are often encapsulated within the methods of the object. This serves two major purposes:

    1 Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Also, an object can be easily passed around in the system. This allows for much greater code re-use.
    2 Information-hiding: An object has a public interface that other objects can use to communicate with it. The object can maintain private information and methods that can be changed at any time without affecting other objects that depend on it thus allowing anyone to work with the object without having to know how it works internally.

Well, thats it for today. Feel free to drop a comment to let me know what you thought of the article and check back soon to see the next part of this series where we will be discussing messages.

Comments :

BeachBum 2006-04-18 #8

Thanks, I'm looking forward to part 2

  • Search For Articles