DEV Community

Zucarelli
Zucarelli

Posted on

Object Orientation - Pillars

Introduction of Object Orientation
Object orientation (OO) is a programming paradigm that organizes code around objects, which can contain data in the form of attributes and behaviors in the form of methods. It is crucial to modern software development as it provides a structured, modular and flexible approach that makes it easier to create efficient, sustainable and easy-to-maintain systems.

Pillar of abstraction
The pillar of abstraction in object orientation is one of the fundamental principles that support this programming paradigm. It refers to the ability to create simplified models and conceptual representations of real-world entities, focusing on the relevant aspects and ignoring unnecessary details. Abstraction allows objects to be created with specific properties and behaviors, encapsulating internal details and interacting with each other in a modular and efficient way. This facilitates understanding, maintenance and reuse of code, promoting flexibility and scalability in object-oriented systems. Abstraction involves the creation of classes and interfaces that define the structure and behavior of objects, offering a simplified and coherent view of the system.

Code example - abstraction:

Image description

Image description

Encapsulation pillar
Encapsulation is one of the pillars of object orientation and refers to the practice of hiding the internal details of a class, protecting its attributes and methods. This is achieved by defining restricted access (public, private, protected) for class members, allowing only specific methods to access and modify this internal data. Encapsulation promotes security by preventing unauthorized access and direct manipulation of class data, and also facilitates code maintenance, since internal changes can be made without affecting other parts of the system. Furthermore, encapsulation contributes to cohesion and low coupling between classes, promoting a more modular and flexible structure.

Getters and setters methods are common in object-oriented programming and provide finer control over accessing and modifying private attributes, allowing the implementation of custom logic during these operations. This contributes to encapsulation and helps maintain data integrity within a class.

Getter (get):

The get canalAtivo method is a getter for the private attribute _canalAtivo.
It allows you to access active channel value from outside the class, providing a controlled way to obtain private information.
Setter (set):

The set canalAtivo(canal) method is a setter for the private attribute _canalAtivo.
It provides a way to modify the active channel value, but may include additional logic or security checks before making the change.

Image description

Heritage Pillar
Inheritance is a fundamental pillar of object-oriented programming that allows you to create a new class, called a derived class or subclass, based on an existing class, called a base class or superclass. Inheritance facilitates code reuse by promoting the creation of a class hierarchy.

Code example - heritage:

Image description

Image description

Pillar of polymorphism
Polymorphism is a fundamental concept in object-oriented programming that refers to the ability of objects of different classes to respond uniformly to method calls with the same name. It allows the same method to be overwritten in the child object, providing flexibility and simplicity in the code.

example of overriding the voo() method:

Image description

Image description

Top comments (0)