Main Content

Basic OO principles

Archive - Originally posted on "The Horse's Mouth" - 2009-05-11 06:05:47 - Graham Ellis

Object Oriented Programming is often described as "data driven", but what does that mean?

For delegates who have been on my Object Oriented courses, I'm reproducing here is a diagram that I develop on the board during the course. And I'm reproducing it with some reluctance, as it's the very development of this diagram - the way the lines go in and it builds up - that help me describe the basic OO principles so powerfully and create "lightbulb moments" for many of our delegates.

Courses that include coverage of the principles of Object Oriented coding include:
Object Oriented Programming in PHP
Perl for larger Projects
Learning to program in Python and Python Programming
Ruby Programming and Learning to Program in Ruby
Java Bootcamp and Learning to program in Java
Lua Programming and Learning to program in Lua

Just a little about the diagram ...

When you're designing a program on OO principles, you think about the data first. Say (for example) you are writing a suite of programs to sell articles of clothing, then you'll think first about an article of clothing - what do you need to know / store about each garment, how do you set up a garment in your program, and what pieces of code do you need to set, manipulate and retrieve that information?

Thinking about the data and the accessors needed will lead you towards the specification of a group of pieces of code that work on that data, which you can discuss with your colleagues and work out what's needed now, and what may be needed in the future.

You can then write a program - a test harness - which will both help you validate your design, and will also allow you to test the code that deals with garments when you have written it.

Well thought through, these design methods allow you to come up with a clean, maintainable, extensible design which naturally offers the programmer who calls you code only facilities that will properly work on this type of data, and also offers a natural separation of the internals of how a garment is made and "works" from how it is used. That's the most natural thing in the world - after all, have you ever thought about how those shoes that you're wearing while reading this article were made?


The OO world has its own language - words like "class", "object", "method", "instance" and "constructor" to describe elements of the principles I have described above. Such single word descriptions are both a blessing and a curse - they're very helpful in discussing code with people who know what they mean, but the tend to obscure the OO principles and just how effective they are from newcomers. Some of these words are on the diagram above in a reddish colour ... and you'll see fully how they fit in place when I welcome you on one of the courses listed above ... or on our C / C++ courses which also cover it in the C++ element, but which I forgot to list earlier.