Pinterest Stumbleupon Whatsapp
Ads by Google

object oriented programmingObject Oriented isn’t just a random buzzword you hear in programming circles. There’s a reason behind the name – but what? Join me as I explore some of the fundamentals of programming concepts and explain just why object oriented programming drives the technology behind any modern software and contrast it to Procedural and Logic Based Programming.

History Of Procedural Programming

When computers were first invented, they needed to be programmed explicitly with simple instructions – and “software” was merely a collection of these extremely simple commands strung together that would run in sequence.

object oriented programming

Initially, these required machine code to be written – move this “bit” from this memory to this location, and perform a logical “and” operation on it with this bit, etc – but soon enough these were abstracted to a higher level using BASIC.

object oriented software architecture

I suspect most of you have come across BASIC (Beginners All-Purpose Symbolic Instruction Code) in school. It’s a perfect example of a procedural programming language. Even my first programming foray was using BASIC on an Amstrad CPC-64. Each line begins with a line number, followed by a simple instruction in human readable language.

Ads by Google

Since procedural languages follow the commands one after the other, it’s generally easy for humans to follow along with whats going on in the program. However, it’s also difficult to make anything beyond a simple learning exercise – which brings us on to the creation of Object Oriented Programming.

Object Oriented?

With object-oriented programming, the idea is to group together related variables and functionality into one object, which represents some kind of complex data structure. That object can then be reused multiple times, or extended to be something even more complex.

For example, a game might have a player object. Each player object in the game represents a single, unique real-life player in our imaginary multiplayer online game. Each player object has a nickname, a current location, an inventory, and a movement rate. Even though every player is unique, we still want them to share the same base-level functionality. Each player might have an move function, which causes the player to move forward X number of squares. Every player may have a different move rate, but when we tell the player to move in one command, it will know how to react according to its own Internet mechanics.

Why is this useful? Taking a more real-life example – because modern graphical user interfaces would be impossible without objects – all operating systems provide a Window object. It’s therefore easy to have a new “window” complete with close and full-screen buttons, and the ability to be moved around – without having to program that yourself. All you need to do is say create a window.

In fact, modern software consists of thousands upon thousands of objects – not just windows, but buttons and form fields, and alert boxes too (which are themselves a special kind of window object) – and it’s only the way they are arranged and the logic of interaction between them that makes this software different to others. It means that programmers and software designers are free to concentrate on making the core mechanics of their program without having to re-invent the wheel every time.

object oriented programming

Another advantage to object-oriented design is that functionality is separated out and invisible to each other. So when the player presses the forward key in our game, it calls the move function in the player object. If we make a small change to how that move is precisely performed within the player object – like jumping instead of walking – then we don’t need to adjust the keyboard-listener. It still calls “move” regardless of what happens internally in the player object – so we can change functionality without breaking everything else.

The same is true in operating systems – if the user suddenly decides to change their window colour to red, then you don’t need to detect that and make the Window red too – it’s all built into the window object.

Inheritance

Once we have objects, we can also extend and inherit them to produce more useful objects with different behaviour or additional functionality. You can re-invent the wheel – if you want. In our player example, perhaps we want to create a “superman” object. Superman is still a player, the same as everyone else – he wants a nickname too, and wants to be listed on the same player leader boards – but instead of the standard move action that walks the player object X spaces forward, we want him to fly instead – moving 10 squares at a time over the top of any objects in the way. By extending the basic player object we can “inherit” all that useful functionality without having to rewrite it all again – but we can still “override” the move function with our special superman flying move!

Object oriented programming is an absolute revelation if you’d only ever experienced procedural programming, and I personally think it’s a shame that that a simple kind of OOP language isn’t taught in junior high school.

One Last Thing: Logic-Based Programming Languages

These are of particular interest to me, as they’re generally most useful for anything related to Artificial Intelligence. Logic-based programming languages, such as Prolog, don’t use commands and instructions in the traditional sense. Instead, they will solve a problem given a set of rules and conditions.

Think of a dinner party you’re hosting for your family. Your aunt can’t sit next to your uncle because they’ll argue; you don’t want two children sitting together because they’ll be little rascals; you certainly don’t want to sit in-between two children. That’s it right there – that’s your Prolog program written. Now just give it a list of children and adults coming to the party, and it’ll output a list of possible seating suggestions!

I hope you enjoyed this beginner level introduction to programming concepts. I’m sorry I couldn’t go into more detail and of course there’s a million things I haven’t touched upon. If you’d like to learn more, let me know in the comments. Perhaps we could do a series of beginner object oriented programming tutorials for various languages if there is enough interest? Be sure to check out our programming related archives too, featuring various tools and programming websites.

Image Credit: ShutterStock

  1. Darshan
    March 1, 2015 at 8:59 am

    James Thanks , you have made things clear on OOP for me. I am going to check your others articles now. I have some great ideas, but don't wanna risk it out as we know the case of Facebook. So I have decided to learn the programming languages which are required. As am an E&Tc Engineer, I guess I have little advantage at learning compare to others.

    Thanks again

  2. muotechguy
    September 15, 2011 at 12:20 pm

    Thanks for the link Tom. I did actually have to cut a significant portion of the article out in order to stick to word limits, but I decided to remove the bare historical facts because I didn't think they would help our readers to understand about why exactly it's called "object oriented" programming. But technically, yes, youre right, I skipped the actual origins of the name and should probably have titled this "What is OOP?" instead ;)

  3. Justin9
    September 7, 2011 at 9:36 pm

    Awesome....!!! can u write a programming article like for people who are just beginning without any knowledge or with just basic html knowledge. thanks a ton ...!!!

  4. Trevor Lenten
    September 7, 2011 at 8:34 pm

    Nice article. I've been wanting to dive into programming for awhile now but haven't quite figured out where to start besides the BASH scripting I've been playing with here and there. 

Leave a Reply

Your email address will not be published. Required fields are marked *