What is Object Oriented Design anyway?

by:

Share:  

A five minute summary of the most hardcore principles of Object Oriented Programming. (Part 1)



You don't know Object Oriented Design

So to make it quick and swift,

Repeat with me:

  • Object Orientation is a programming paradigm
  • Object Oriented Analysis refers to analysing the problem.
  • Object Oriented Design refers to designing the solution.
  • Object Oriented Programming refers to building the solution.

So What is an Object?

An object is a self-contained entity made up of an identity, attributes (properties) and behaviour (methods). Objects are not always physical or visible items. Ideally, an object should be a noun. That is, if we can put the word the in front of an entity, it should relate to an object.

What is a Class?

A class is a blueprint which defines how an object will be created. A class describes how the object will be but does not represent the object itself.

Classes are used to create objects. A class has a name/type and describes the attributes/properties and behaviour/methods.

Let's take an example at a class called Person.

name: Person
attributes: name, age, gender, address
behaviour: speak(), walk(), eat()

After the Person class is defined, we can create objects based on that class.

Each object is an instance of a class; this is referred to as instantiation.

Each object will have its own identity, attributes and behaviour which is independent from other objects.

Abstraction

Abstraction refers to the principle of focusing on the essential qualities of an idea rather than the detail.

Abstraction means discarding the irrelevant details of an idea or concept and focusing on the base qualities.

Encapsulation

Encapsulation refers to the idea of surrounding and protecting the attributes and behaviours of a class and bundling them together as well as to restrict access to that class or objects of that class.

This is also called information or data hiding.

The idea is that an object should not reveal anything about itself except what's absolutely necessary to other external parts of a program which is also commonly referred to as black boxing.

Encapsulation is responsible about reducing dependencies between different parts of the program so that a change in one part of a program does not cascade down to other parts of the program.

As a rule, one should hide as much as possible.

Inheritance

Inheritance allows code reuse by inheriting properties and behaviour based on an existing class.

The class being inherited from is called the superclass / parent class / base class.

The class which is inheriting is called the subclass / child class / derived class.

In languages like C++, multiple inheritance is possible so a child class can inherit from multiple parent classes.

In languages like Java, Objective C, C# or Ruby, single inheritance is more prevalent.

Inheritance reflects an "is-a" relationship.

A Dog is an animal
A Cat is an animal
An Employee is a person
A Customer is a person
A BMW is a car which is a vehicle

Polymorphism

Polymorphism means exposing an object in multiple forms.

  • Polymorphism allows overloading so that for example, operators can be overloaded so they share different behaviour.

For example, in Javascript, the plus sign ( + ) can be used for integer addition or string concatenation.

  • Polymorphism allows overriding so that child classes can override the default attribute or behaviour of a property or method defined in the parent class.

I thoroughly enjoyed Simon Allardice's explanation on `Introduction to Object Oriented Programming a couple of years back.

I would recommend the video as an introduction should you feel the need to understand more object oriented programming.

Your turn...

What does object orientation mean to you? Please share it with us by leaving a reply below.

More to come soon in Part 2. Stay tuned.


About the Author

Alvin Luchmun
Alvin Luchmun is a freelance developer, trainer and co-founder at and currently lives in London. Alvin is passionate about anything tech/biz related but is also a firm believer in agile clean code, he loves preaching about code to fellow humanoids!.

Leave a comment