Skip to content
Home » OOP: Object Oriented Programming. Object Oriented Programming (OOP) is a… | by Joseph Maurer | Geek Tradition

OOP: Object Oriented Programming. Object Oriented Programming (OOP) is a… | by Joseph Maurer | Geek Tradition


Object Oriented Programming (OOP) is a programming paradigm that’s the cornerstone of recent software program improvement. Whereas OOP isn’t the one programming paradigm that exists, I’d argue it’s an important to have a agency basis of, and when used accurately, can result in stronger and extra sturdy software program. However what’s OOP and how will you be certain that to grasp it effectively? Let’s discover.

At a excessive stage, in OOP there are 3 essential pillars to grasp for getting OOP down:

  • Encapsulation with courses
  • Inheritance
  • Polymorphism (an important by far)

Encapsulation is the flexibility to surround knowledge that describes the thing and the features used to control that knowledge into one module container.

In OOP these are sometimes known as courses and are on the middle of the paradigm. The ensuing variable when the variable is asserted is named an object. An necessary half is abstraction in order that solely mandatory options are uncovered.

  • Personal/Inner: Strategies and properties are accessible from different strategies of the identical class. Something outdoors of the category shouldn’t be capable to entry these members/strategies. That is sometimes denoted by Personal or Protected.
  • Public/Exterior: Strategies and properties are accessible from outdoors the category.

An instance can be when you had been programming a card sport. In your card dec class, would you need another person to switch the variety of playing cards within the deck? Most likely not.

Inheritance is the flexibility to take an current class and lengthen its performance to type one other class.

Why is that this necessary? As a result of it helps reusability with code reuse. It’s because the brand new class has entry to the entire dad or mum performance. The kid class simply wants so as to add new attributes and strategies which can be particular to its wants.

  • Generalization is the relation such that the subclass is a variation of the dad or mum. I.e. a pickup truck “is-a” car.
  • Specialization is the connection such that the category “has-a” subclass. I.e. an car “has-a” engine.

Polymorphism is the flexibility of comparable objects to reply otherwise to the identical message.

The ultimate pillar of OOP is intently associated to inheritance and but is arguably much more necessary. The prefix poly means many; morph means type. Polymorphism then refers back to the means of a single sort or class to take many kinds.

How is that this completed? With methodology overriding:

Within the instance above, you’ll be able to see that each the electrical automotive and the pickup truck inherit from Vehicle and each override the Begin conduct since each have vastly totally different wants. An electrical automotive doesn’t want to start out an engine whereas a pickup truck would (assuming it’s of the fuel selection).

Key Takeaways

  1. Nicely designed objects manipulate the information or state of an object by passing messages by means of the thing’s interface.
  2. Controlling an object by means of its interface ensures it behaves in a protected method and that the interior state stays legitimate.
  3. The power to mannequin the true world is a vital benefit of OOP.
  4. Objects have to be self-contained in order that they will stand on their very own.

Leave a Reply

Your email address will not be published. Required fields are marked *