You don't know OOP, the heater does♨️
Tags: abstract, programming, bases, beginners
Published: 2023-04-18 02:21:48


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pdqng43weg1u5f3dyzdo.jpg)Once upon a time in an enchanted forest there was a magic box that contained a variety of objects with unique identities, states and behaviors. Each object knew its purpose, but could not perform a function on its own. On a very cold winter day, the resistor, an object that could heat, realized it needed the ability of energy to function. The battery, an object that could provide energy, offered the resistor the ability to **_inherit_** its energy, which allowed the resistor to heat. However, the resistor also needed someone to help disperse the heat it produced. The fan offered to help, but it also needed to **_inherit_** the battery's energy. Together, the objects created a larger class called "Heater."

When they started all the systems, they realized that the fan did not work. They discovered that the battery power functionality did not work for the fan because it used AC current, while the resistor used DC current. The battery, which could provide power to both objects, decided to implement an interface to allow each to implement its own functionality through **_polymorphism_**.

After solving this problem, they realized that they could not know the temperature at which the resistor was operating. The larger class, the Heater, asked the resistor if it had **_encapsulated_** the temperature and could not see or manipulate it. The resistor explained that it was designed that way and asked if that was a problem. The older class explained that he could control the fan and know its speed, so he needed to be able to control the temperature of the resistor as well. Finally, the resistor exposed its **_encapsulated_** properties, which allowed the senior class to function perfectly.

At some point, the battery died and everyone knew they were going to freeze. However, the electrical outlet, which had been frozen, offered to help and provided them with power. The senior class asked him how he could do this, and the electrical outlet explained that the senior class should implement power functionality through him and send charge to the battery. With the help of the electrical socket, the objects were able to survive the cold winter. 🤩

## Detail enlargement

In terms of OOP concepts, a good implementation of **_encapsulation_** is observed in the resistor and the exposure of its encapsulated properties when needed. **_Inheritance_** was implemented when the resistor inherited the battery's ability to provide power and when the fan and resistor inherited power from the battery through the larger class. **_Polymorphism_** was used when the battery implemented an interface to allow the resistor and fan to implement their own functionality. Finally, the creation of a larger class to **_abstract_** the operation of several objects is noted.

Overall, the story is a good analogy for understanding the fundamental concepts of object-oriented programming, such as **_encapsulation_**, **_inheritance_**, **_polymorphism_** and **_abstraction__**.

First, **_encapsulation_** refers to the protection of the data and behaviors of a class to prevent its direct access from other classes. In the story, the resistor had its temperature information encapsulated, which caused problems for the heater. However, by exposing its encapsulated properties, the problem was solved and the heater was able to function correctly.

Second, **_inheritance_** refers to the ability of one class to inherit properties and behaviors from another class. In the story, the resistor inherited the ability to power itself from the battery and the fan inherited the ability to disperse heat from the heater.

Third, **_polymorphism_** refers to the ability of different objects to respond to the same message in different ways. In the story, the battery implemented an interface to power the resistor and the fan differently, through **_polymorphism_**, to solve the problem that they both used different types of current.

Finally, **_abstraction_** refers to the ability of a class to hide the details of its implementation and present only the relevant aspects to the user. In the story, the heater class was presented as an abstract entity that included the resistor, fan, and battery, but hid the details of its implementation.

In summary, the OOP heater story is a good way to understand the key concepts of object-oriented programming. By giving it a more magical and enchanting tone, it makes it more appealing to the general public and makes it easier to understand these concepts. We hope this story will inspire more people to learn about object-oriented programming and improve their OOP skills. 😎🚀

Y entonces luego llegaron Batman y los Power Rangers y... to be continued!! 🤣