Object Oriented Programming

Object Oriented Programming is a programming paradigm in which we work around the objects.

In OOP, we create objects and objects have
  • Attributes/Properties
  • Behaviours
which are defined inside the class.

Class is a template which contains attributes and behaviours of objects.
Object is the instance of class.

Real life analogy of Classes and Objects:

  • Animal is a class. Its instances are Lion, Tiger, Monkey, and Zebra etc. These are the objects of Animal class. They have properties and behaviors like an object has. For example, they have properties like:
    • Lion is brave.
    • Monkey is intelligent.
    • Tiger is powerful.
    • Zebra has beautiful stripes.

    In the same way, they also have some behaviors like:
    • Lion sleeps most of the time.
    • Monkey can jump.
    • Tiger hunts brilliantly.
    • Zebra eats grass.

We have class named animals. The objects will be lion, monkey, zebra etc. objects have attributes, lion is brave. and behavior, monkey can jump. These behaviors and attributes are defined inside the class.


Class

Animals

Properties (data members):

brave, intelligent, beautiful

Behaviors (member functions):

walk(), eat(), sleep()

Objects

Lion

Elephant

Donkey

Zebra

flowchart

What happens in C++:

An object created as an instance of a class will have all the properties and behaviors of that class. For example, if the animal class has properties like brave, intelligent, magnificiant. And we create two objects lion and donkey. Then lion and donkey both will inherit all the properties. If lion is magnificiant, the donkey will also be magnificiant if it is the instance of the same class.

Why OOP:

  • It makes your code easier to read.
  • Makes code 'DRY' - Do not Repeat Yourself.
  • Easier to find errors
  • Code looks beautiful and structured.
  • Code will be reusable.
  • Less time consumption.

Here is a roadmap to OOP:

1. Classes and Objects:
Learn about concept of classes and objects and how they interact.

2. Four pillars of OOP:
Study the four pillars of OOP.
  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction
3. Class Relationships:
Study different types of class relationships, such as aggregation, association, and composition etc.

4. Study Design Patterns:
Study about the different design patterns.

5. Error Handling and Debugging:
Learn how to handle exceptions in OOP.

6. Software Development Principles:
Learn about software development principles.

Now move to the advanced OOP concepts and start developing softwares.