Object Orientation

Object orientation. The art of design..

One issue I’ve seen over the years is that some programmers focus on syntax over object oriented design. If you work in a large shop, this may be acceptable as the senior level developers may provide the object oriented design for you.

If you’re interested in object oriented programming, I would suggest you focus on the paradigm itself. Syntax is language specific and poor code regardless of language is poor code. Period. Look at the overall design. Is it object oriented? You can do object oriented designs regardless of language as you’re dealing with objects, data and actions. This is where the focus should initially be. Not on the specific syntax of some specific language.

Learn to think in terms of object orientation and your designs and subsequently your code will certainly get better and be easier to maintain.

Quick Overview

The 4 main components for object oriented programming are:

Encapsulation

Encapsulation is the process of enclosing data and actions within some object. The actions to be performed on this object are called via an interface from the outside. The actual execution performed on the object is carried out by the object itself. These internal workings are hidden from outside the object.

Data Abstraction

This is an iterative process where the details of some thing is broken down into its component parts. Once this is done, we can start to group base characteristics from other characteristics. Back in my college days they would use a car for an example, then ask about a different types of cars (sports car, sedan, SUV). Next they went on to ask about trucks (and the different types of trucks). Going through an iterative data abstraction process, the result was a vehicle base class. (everything above is, in fact, a vehicle). Next we could create a car and a truck class by inheriting from the vehicle class. The point of data abstraction is to identify all like properties/attributes/actions and abstract those out.

Polymorphism

Polymorphism promotes re-usability due to many (poly) implementations. This one ‘trick’ can really make your code extensible, easier to read and debug. There are multiple ways to achieve this (overload, override, etc) but what we’re trying to do here is to wrap a piece of functionality into a re-usable piece of code. Think of something like a piece of code that adds 2 numbers and returns a result. We could call this a polymorphic call by having different add methods. One may take 2 integers, another integer and float, etc. Same name but implemented differently (where the details are wrapped/hidden within the method)

Inheritance

Inheritance is the process for one ‘thing’ to inherit (or receive) the properties and actions from another ‘thing’. This too is huge for re-usability. When we talked about data abstraction above, our car and truck classes ‘inherited’ from the vehicle class.

Very High Overview

Above is a very high level overview only. Object oriented design is language agnostic. It doesn’t matter which object oriented language you use, if you don’t have a good understanding of the 4 points above (encapsulation, data abstraction, polymorphism and inheritance) you won’t be writing very good object oriented code. Programming should be the LAST thing you do. That’s where syntax and knowing the nuisances of a specific programming language comes into play. Knowing how to efficiently implement specific things (threading, data structures, memory management, etc.) are very important. But again, in my opinion it all starts with object oriented design. I strongly suggest that you read more on the areas above and do a lot more research. Read about it, ask more senior level developers about it, try it out on your own. Learn, then learn some more and then learn some more. Enjoy the trip.