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?
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?
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
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
Each object will have its own identity, attributes and behaviour which is
independent from other objects.
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 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
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 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
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 means exposing an object in multiple forms.
- Polymorphism allows overloading so that for example, operators can be overloaded so they share different behaviour.
- 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.
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.