top of page
  • Writer's pictureCristian Duque

Object-Oriented Programming (OOP)

Updated: Sep 1, 2023


By the publication date of this post, it's common to use programming languages such as Java, C#, Javascript, and Python. Object-Oriented Programming is a programming style that was first developed in 1960 with the creation of Simula by the Norwegian computer centre in Oslo.


OOP represents real entities as simple objects to structure pieces of code properly. Classes are utilized to create or instantiate the things needed to map life scenarios in code terms.


A class is a blueprint for an entity, the "thing" mapped to a class. It contains properties (data) and methods (behaviours) that define the class members. In OOP, everything is an object.


For example, let's consider a Book. In code, it would be represented as a class with properties such as Color, Topic, Number of Pages, and methods like print, write, and distribute. To create a new book, we would instantiate the book class and define its properties and behaviours to achieve our desired product.


The four pillars in OOP that can help us write better-structured code:


1. Abstraction:

It reveals only essential information rather than sharing all of the implementation details. It aims to keep plumbing code and secure functionalities hidden from external sources. For example, in a book, we are only interested in reading the content rather than the printing or shipping details.

2. Encapsulation:

It groups data and functions within a single unit or class to protect them from external usage. By keeping the state and logic of an object isolated, we can ensure that it remains secure.


3. Inheritance:

It creates a parent-child relationship between objects where properties and methods can be shared from a base or parent class. Child objects can extend parent functionalities. For example, an ebook or physical book can inherit properties from a base book, such as the number of pages, chapters, and subject.


4. Polymorphism:

It implements different behaviours from a standard class. While multiple shapes can be used, the main object remains constant. For example, consider printing a book using two different approaches: hardcover and paperback. The class (Book) is the same, including the printing behaviour, but the way it is printed using these two approaches is different.



Benefits of OOP

- Simplicity: Clear representation of real entities into objects. Expose the core functionalities of an object by using abstractions.


- Reusability: Inherit class members from parent classes. Define common behaviours of classes to be implemented in different ways.


- Flexibility: Using Composition (interfaces, abstract classes) and Inheritance to add or adapt code changes appropriately.


- Security: Hide concrete details with abstractions and restrict class member access through encapsulation.


Drawbacks of OOP

- Overusability: Analyze the test case to define which paradigm is a better option. Consider checking other paradigms like procedural or functional programming.


- Complexity: Larger structures are challenging to handle and divide if you need to familiarise yourself with clean coding practices.


- Performance concerns: Intensive dynamic executions such as polymorphism in your software can lead to slower time responses and reduced optimization.


Checkout my video:


2 views

Recent Posts

See All

Commentaires


bottom of page