Object Oriented Programming (OOP)

Havisha
3 min readJun 29, 2018

Better overall compared to procedural or Functional Design

Easier to develop large projects

Easier to modify projects

Changes to one object need not affect another

Object vs Class :

A class is the definition of the “thing”

An Object is the actual “thing”

Example: class is blue print and object is a house itself.

Constructor:

The purpose of the constructor is to initialize all member variables when an object of this class is created.

Private vs Public vs Protected:

Public: The type is available to code running in any assembly that references the assembly in which the class is contained.

Internal: The type is available to any code within the same assembly, but not available to code in another assembly.

private: The type is only available to code within the class that contains it. You can only use the private access modifier with nested classes. This is the default value if you do not specify an access modifier.

protected: The type is only accessible within its class and by derived class instances.

Encapsulation:

All aspects of the object are “bundled” together into one entity, or package, including data and processes that act on the data.

Encapsulation is the process of providing physical structure to implement the outcomes (Entity-Property-Behaviour) of abstraction. Protect the property from accidental or unauthorized access. It is about hiding the information at implementation level from unauthorized access by restricting the access to data and providing public methods as interface.

Abstraction is a though process to identify Entities-Properties-Behaviors. it is about hiding complexity at design level thought process by ignoring the unwanted details and focusing on what is required.

Inheritance: Defining a new object in terms of a predefined object

“IS A”: “A GradStudent “is a” Student”

Composition: Defining a new object that is “composed” of other, predefined objects.

“Has A” : A car “has a” Body … A car “has an” Engine… A Car “has” Wheels

Polymorphism:

Greek roots — poly(“many”) morphe(“forms”)

Dynamic Polymorphism: Uses the same interface for methods on different types of objects.

Overloaded methods… Overridden methods… Polymorphic objects…

Overloading: Several methods that achieve the same result in different ways, such as locking your car door…

Overriding: Methods inherited from parent class redefined by the child class…

Polymorphic Object:

Multiple referencing … when a parent object able to reference any of its child objects … or grandchildren… or great-grandchildren…

Benefits of OOP

Encapsulation — Reduce complexity + increase reusability

It regroups and function together

Abstraction — Reduce complexity + isolate impact of changes

we hide details and show only essentials

Inheritance — Eliminate redundant code

Polymorphism (poly means many and morph-ism means form) — Refactor ugly switch/case statements

--

--