Object Oriented Programming Concepts

OOP OOP is a programming paradigm that represents the concept of "objects" that have data fields (attributes that describe the object) and associated procedures known as methods. Objects, which are usually instances of classes, are used to interact with one another to design applications and computer programs.

Each module is split apart into self-contain objects and each object contains its own data, logic and function. In order for these modules to function as one, they should communicate with each other.

It is problem solving technique that is based on the real world scenario/modeling.

It is a design philosophy that implements modular programming that enables developers to reduce dependencies (tight coupling) and promotes high cohesion(readability, maintainability, reusability, extensibility,  and traceability) that makes more codes manageable.

The problems with traditional programming (Procedural Programming):
  • Too huge to handle.
  • Not ideal for team development.
  • Too difficult to trace and debug.
  • Limited reusability and extensibility.
  • Cascading effect (when editing one module, other modules will be affected) due tightly coupling issue.
  • Too difficult to test.
  • Take longer time to compile therefore slow development.
  • Abstraction is too difficult.
  • And many more...
Can OOP solve these problems?

The answer is yes. Just imagine a car production where the parts are separated from each other and can be connected through knots volts and wire. If one part is defective, it can be easily replace. Easy to diagnose/troubleshoot, upgrade, and extend. This is what i called it real world modeling.

Advantages of OOP for developers:
  • Avoid spaghetti code. Developers spend more time in debugging/tracing than in developing so readability and traceability is very important during debugging.
  • When working as a team, task can be easily separated and integrate.
  • Delivery of upgrades and corrections are easier to ship. Since it is modular, only the affected updates will be ship.
  • Faster compilation and testing. Stable codes needs not be to compile during development.
What builds around OOP?

Objects and Classes

Whenever we build application, we always work on classes and objects. These two are the models of what we are trying to build.
  1. Object
  2. In real word, an object is a thing that has independent identity from one another. It has attributes (color, shape, state) and behaviors (what can they do: fly, walk, talk and etc.) regardless of what families they came from.

    In OOP, we use the concept of a real world object. Objects in OOP have their own identity separate from one another, properties, and behaviors.“In OOP, objects are not always physical and visible items. They are NOUNS or SUBJECTS. Examples of these are events, dates, account and timer.”

    Objects and classes are related to each other and knowing class will brings to a complete understanding of these two.

  3. Class
  4. In order implement reusability and inheritance in OOP, it easier to create a class that represents the properties and behaviors of all objects. So we can create one class and create multiple objects out it.

    “Class is best described as template or blueprint of objects and objects are instance of a class.”

    “Classes are user defined types that can be made up of primitive types or collections of classes”.

    Meaning class is not the real object but it is only a representation of object.

    Essential Components of a Class:
OOP Real WorldExample
Type NameCat
Properties/Data AttributeColor, Height
Methods/ Operations BehaviorRun, Walk


Fundamental Principles of Object Oriented Programming?

In order to achieve object-oriented principle, there are 4 fundamental approach to make classes and objects working together:
  1. Abstraction
  2. “Abstraction (from the Latin abs, meaning away from and here, meaning to draw) is the process of taking away or removing characteristics from something in order to reduce it to a set of essential characteristics.”

    In OOP, it is the process of hiding all but the relevant data about an object in order to reduce complexity and increase efficiency. It focuses on exposing essential/relevant qualities of objects rather than the details. It called the heart of OOP because whenever we create classes we always do abstraction.

  3. Encapsulation
  4. This is were decoupling comes in OOP wherein we want to contain the logic and data within one class so that we can reduce dependencies. If one part of the code was changed, it will not affect the others.

    It is also called "information hiding". An object has to provide its users only with the essential information for manipulation, without the internal details.

    In software development, business logic should not be expose. We should limit the access of vital implementation or formulas in order to protect it from tampering.

  5. Inheritance
  6. This is one of the fundamental principle of OOP. It allows a class to "inherit" (behavior or characteristics) of another, more general class.

    Inheritance is a great form of code reuse where data definition, logic, and validations will be defined in a parent class and can be applied to child classes that inherits them.

  7. Polymorphism
  8. In OOP, objects have the ability to transform in many forms during its implementation.

    The ability of classes to perform different functionalities while sharing the same interfaces.

    Real World Examples:
    1. A person that can speak 2 languages
    2. A BlueRay player than can also play DVD.

    OOP Example:
    Method Overriding, Method Overload, and shadowing