<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Flavio Rozendo</title>
    <description>The latest articles on DEV Community by Flavio Rozendo (@f_rozendo).</description>
    <link>https://dev.to/f_rozendo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F461091%2F180319c1-01b4-4e25-a43e-380ae481d8ad.png</url>
      <title>DEV Community: Flavio Rozendo</title>
      <link>https://dev.to/f_rozendo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/f_rozendo"/>
    <language>en</language>
    <item>
      <title>Object-Oriented Programming - The Four Pillars</title>
      <dc:creator>Flavio Rozendo</dc:creator>
      <pubDate>Sat, 05 Oct 2024 20:10:56 +0000</pubDate>
      <link>https://dev.to/f_rozendo/object-oriented-programming-the-four-pillars-k2a</link>
      <guid>https://dev.to/f_rozendo/object-oriented-programming-the-four-pillars-k2a</guid>
      <description>&lt;p&gt;We are back again to talk about object-oriented programming. &lt;a href="https://dev.to/f_rozendo/object-oriented-programming-the-bases-1b7e"&gt;In the first article&lt;/a&gt;, we talk about the history of the paradigm and some basic concepts. It's a good idea to read this article before this one, once the concepts showed there will be used to talk about the four pillars of OOP: &lt;strong&gt;Abstraction&lt;/strong&gt;, &lt;strong&gt;Encapsulation&lt;/strong&gt;, &lt;strong&gt;Inheritance&lt;/strong&gt;, and &lt;strong&gt;Polymorphism&lt;/strong&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Study Case
&lt;/h2&gt;

&lt;p&gt;To better understand the four concepts, we will use an application written in Java. This case study simulates a real-world banking application to demonstrate how those principles work. &lt;br&gt;
The code is on this &lt;a href="https://github.com/frozendo/bank-oop-case" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Abstraction
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Abstraction&lt;/strong&gt; involves structuring our system into low and high-level components.&lt;br&gt;
&lt;strong&gt;Low-level&lt;/strong&gt; components are classes and objects close to what our application does. We can say that these components do the dirty work, dealing with requests, and changes, and sometimes coordinating a complex flow. &lt;br&gt;
On the other hand, &lt;strong&gt;high-level&lt;/strong&gt; components are classes that represent abstract concepts. They don’t have a specific function in the application but can be reused in different contexts, assisting the low-level components in their tasks.&lt;/p&gt;

&lt;p&gt;In our study case, we have three classes that can represent the use of abstraction: &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/account/BankAccount.java" rel="noopener noreferrer"&gt;BankAccount&lt;/a&gt;, &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/account/IndividualAccount.java" rel="noopener noreferrer"&gt;IndividualAccount&lt;/a&gt;, and &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/account/EnterpriseAccount.java" rel="noopener noreferrer"&gt;EnterpriseAccount&lt;/a&gt;. The class &lt;strong&gt;BankAccount&lt;/strong&gt; represents a generic account, controlling all the balance updates and account changes, but it doesn't represent any specific account type. We have two low-level classes for account type: &lt;strong&gt;IndividualAccount&lt;/strong&gt; for persons, and &lt;strong&gt;EnterpriseAccount&lt;/strong&gt; for companies. These two classes are used across the application to execute user requests, using BankAccount as its basis. &lt;/p&gt;

&lt;p&gt;A good OOP software is a balance between low and high-level classes. However, it’s important to note that there aren’t just two layers of components. We can have &lt;strong&gt;multiple layers&lt;/strong&gt;, as many as needed for a well-structured design. A class that appears high-level from one perspective may be considered low-level from another. In the example we use above, &lt;em&gt;InvididualAccount&lt;/em&gt; and &lt;em&gt;EnterpriseAccount&lt;/em&gt; are low levels from the point of view of &lt;em&gt;BankAccount&lt;/em&gt;. At the same time, these two classes are high-level components from the point of view of the other components in the application, once they are in a layer above them in our design.&lt;/p&gt;

&lt;p&gt;Ultimately, the main reason for abstraction is to &lt;em&gt;simplify the code&lt;/em&gt;, create &lt;em&gt;more manageable and reusable&lt;/em&gt; classes, and hide complex functionality. A high-level class aims to make an object easy to use and understand.&lt;br&gt;
A good design using abstraction separates &lt;strong&gt;what&lt;/strong&gt; needs to be done from &lt;strong&gt;how&lt;/strong&gt; it is accomplished. A low-level object understands what it requires from the high-level object but doesn’t need to know how it performs its tasks. This way, we create a layer separating the use of a code and its implementation. Also, if we make the right separation between those concepts, high-level classes hardly change, which makes maintenance easier. &lt;/p&gt;

&lt;h2&gt;
  
  
  Encapsulation
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;OOP&lt;/strong&gt; is based on objects and the interactions between them. But we don't want to allow free communication between all objects, and sometimes we need to keep an object’s data, or part of it, hidden from the rest of our code. This process is known as &lt;strong&gt;Encapsulation&lt;/strong&gt;. &lt;br&gt;
Encapsulation can be used for different reasons. First and perhaps most important is &lt;em&gt;security&lt;/em&gt;. As we know, an object is based on state (properties) and behavior (methods). Therefore, given its context, it must ensure its state is valid and consistent. When we hide some information, we want to control who can access and principally change the object’s state. If the state can be affected by anything, it could lead to mistakes that impact this object's integrity.  &lt;/p&gt;

&lt;p&gt;Again, the &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/account/BankAccount.java" rel="noopener noreferrer"&gt;BankAccount&lt;/a&gt; class can give us a good example of encapsulation. We must reduce the objects that can update the user's &lt;code&gt;balance&lt;/code&gt;, once a wrong update of this value can leave us with big issues. So, the balance property is private and the only way to update it is using the method &lt;code&gt;updateBalance&lt;/code&gt;. This gives BankAccount control of the changes, and if any rule is broken, the class can deny the change. &lt;/p&gt;

&lt;p&gt;Another benefit of Encapsulation is that it &lt;em&gt;simplifies the code&lt;/em&gt;. We can hide complex algorithms, making only the object owner of the code aware of their implementation. The other objects don’t need to know details. They use the method provided, and how things work under the hood is irrelevant to them.&lt;br&gt;
Note the &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/payment/Payment.java" rel="noopener noreferrer"&gt;Payment&lt;/a&gt; class in our study case. This class has the &lt;code&gt;executePayment&lt;/code&gt; method, which interacts with the bank account object and is used by &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/payment/TransferPayment.java" rel="noopener noreferrer"&gt;TransferPayement&lt;/a&gt; and &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/payment/DebitPayment.java" rel="noopener noreferrer"&gt;DebitPayment&lt;/a&gt; classes. Those classes only call the method and don't know how it works. Of course, this is not the case with a complex algorithm, but introduces the idea of hiding details from external classes. &lt;/p&gt;

&lt;p&gt;We use the access modifiers to achieve effective encapsulation. The most common are &lt;em&gt;private&lt;/em&gt;, &lt;em&gt;protected&lt;/em&gt;, and &lt;em&gt;public&lt;/em&gt;. In a good code design, nearly all the properties should be private. In some cases, when we want to grant child classes access to some properties from the parent class, those properties can be protected. This ensures that no one can directly access the object state. &lt;br&gt;
The public access modifier should be used only for methods, and only a small set of them, as we don’t want to expose all the object behavior. Those methods will act as a gateway, giving access to the object's current state and providing ways to change it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inheritance
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Inheritance&lt;/strong&gt; is a mechanism that enables us to share properties and methods. We can create a single code that will be reused throughout the application. Then we can create classes that inherit this code, allowing them to use and redefine it as necessary.&lt;br&gt;
The class that inherits is known as a &lt;strong&gt;child class&lt;/strong&gt;, &lt;strong&gt;subclass&lt;/strong&gt;, or even &lt;strong&gt;derived class&lt;/strong&gt;. The inherited class is known as a &lt;strong&gt;parent class&lt;/strong&gt;, &lt;strong&gt;superclass&lt;/strong&gt;, or &lt;strong&gt;base class&lt;/strong&gt;.&lt;br&gt;
A parent class usually represents something abstract, which allows further definitions by the child class. When inheriting from a parent class, a child class can do one of three things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the parent code completely, without changes.&lt;/li&gt;
&lt;li&gt;Reuse the parent code partially by mixing it with your code&lt;/li&gt;
&lt;li&gt;Reset the parent code completely, and rewrite the behavior for its needs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Inheritance can be done using an interface, a concrete, or an abstract class. The child class can also be concrete or abstract. However, an abstract child class cannot be instantiated by itself; it requires another class to inherit from it. A child class uses the &lt;strong&gt;override&lt;/strong&gt; technique to modify the behavior of methods inherited from the parent class.&lt;/p&gt;

&lt;p&gt;In our application, the classes that make deposits and withdraw use inheritance. &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/movement/DepositMovement.java" rel="noopener noreferrer"&gt;DepositMovement&lt;/a&gt; and &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/movement/WithdrawMovement.java" rel="noopener noreferrer"&gt;WithdrawMovement&lt;/a&gt; inherit from the interface &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/movement/Movement.java" rel="noopener noreferrer"&gt;Movement&lt;/a&gt;. The interface defines a contract and ensures a common behavior between components. The classes implement this interface, inheriting the method &lt;code&gt;movementMoney&lt;/code&gt;. The classes &lt;em&gt;BankAccount&lt;/em&gt;, &lt;em&gt;IndividualAccount,&lt;/em&gt; and &lt;em&gt;EnterpriseAccount&lt;/em&gt; are also examples of inheritance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Problems
&lt;/h3&gt;

&lt;p&gt;Inheritance is extremely powerful and useful. However, there are also some downsides.&lt;br&gt;
First, it creates a &lt;em&gt;strong dependency&lt;/em&gt; between parent and child class that can make changes and evolutions difficult. When the parent class is modified, all the child classes below it will be affected. The &lt;em&gt;deeper&lt;/em&gt; the inheritance hierarchy, the more complex it becomes to change and maintain the code.&lt;br&gt;
Another issue is that inheritance is &lt;em&gt;defined at compile time&lt;/em&gt;, so once the bind between classes is done, it won't change. This makes the code inflexible.&lt;br&gt;
Inheritance can also &lt;em&gt;break or weaken the encapsulation&lt;/em&gt; since a child class can access more things than is desirable.  &lt;em&gt;Tests&lt;/em&gt; can also be hard when we have an inheritance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Composition
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Composition&lt;/strong&gt; is a technique that allows a class to reference objects of other classes in its instance variables. This establishes a &lt;strong&gt;"has-a"&lt;/strong&gt; relationship between the classes, where one class contains an object of another class. This can be a better option in situations where we can use inheritance.&lt;br&gt;
Composition offers solutions to some of the challenges associated with inheritance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We can change the behavior of a class at runtime by changing the object instance.&lt;/li&gt;
&lt;li&gt;We can reduce duplication but with loose coupling between classes.&lt;/li&gt;
&lt;li&gt;Avoid the hierarchy hell, and keep classes simple and modular.&lt;/li&gt;
&lt;li&gt;It's easier to test, once we could change the instance used at runtime.&lt;/li&gt;
&lt;li&gt;Promotes better encapsulation, once the class used in composition will expose only what it wants.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In our application, the Payment class uses composition. &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/payment/TransferPayment.java" rel="noopener noreferrer"&gt;TransferPayment&lt;/a&gt; and &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/payment/DebitPayment.java" rel="noopener noreferrer"&gt;DebitPayment&lt;/a&gt; don't inherit &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/payment/Payment.java" rel="noopener noreferrer"&gt;Payment&lt;/a&gt;. Instead, they use an instance to call the method on the base class.&lt;/p&gt;

&lt;p&gt;Despite these benefits, inheritance should not be dismissed entirely. There are cases when it can be a good option:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When there is a clear &lt;strong&gt;“is-a”&lt;/strong&gt; relationship, that is, when a class is a specialization of another.&lt;/li&gt;
&lt;li&gt;When multiple classes share a significant amount of code, and you want to avoid duplication.&lt;/li&gt;
&lt;li&gt;When we want to extend the functionality of a code that is external to our application, as a framework or a library&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As always, it depends on the specific context. The better option will depend on the requirements and constraints of the project. &lt;em&gt;Composition offers more flexibility and promotes better design practices&lt;/em&gt;. &lt;em&gt;Inheritance can be appropriate for clear hierarchical relationships and shared behavior&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Polymorphism
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Polymorphism&lt;/strong&gt; is one of the fundamental pillars of OOP, and at least for me, the most difficult to understand and explain. &lt;br&gt;
First, it's closely related to &lt;em&gt;inheritance&lt;/em&gt;. When we work with inheritance, we create a hierarchy between classes, where a parent class has a set of child classes.&lt;br&gt;
In this scenario, it is common for methods in the parent class to be reused by all child classes. But how can we have a single method that accepts any child class as a parameter? &lt;em&gt;Polymorphism&lt;/em&gt; provides a solution to this challenge.&lt;br&gt;
Polymorphism allows an object to be &lt;em&gt;treated&lt;/em&gt; as an instance of its parent class or an implemented interface. This means we can have a method with a parent class or interface as its parameter, allowing it to accept any object of the child classes. So a single method to handle various objects as if they have a common type.&lt;/p&gt;

&lt;p&gt;However, this approach has a limitation: methods defined outside the parent class or interface cannot be accessed. If a child class defines a new behavior, it will not be accessible through polymorphism.&lt;/p&gt;

&lt;p&gt;There are two types of polymorphism. The first type, &lt;strong&gt;runtime polymorphism&lt;/strong&gt;, occurs when a child class &lt;em&gt;overrides&lt;/em&gt; a method from the parent class. With this, we can change the method's behavior on the child class during runtime. The second type, &lt;strong&gt;compile-time polymorphism&lt;/strong&gt;, occurs when a child class &lt;em&gt;overloads&lt;/em&gt; a method from the parent class. This changes the method’s behavior before the application starts.&lt;/p&gt;

&lt;p&gt;Again, the classes &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/account/BankAccount.java" rel="noopener noreferrer"&gt;BankAccount&lt;/a&gt;, &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/account/IndividualAccount.java" rel="noopener noreferrer"&gt;IndividualAccount&lt;/a&gt;, and &lt;a href="https://github.com/frozendo/bank-oop-case/blob/main/src/bank/account/EnterpriseAccount.java" rel="noopener noreferrer"&gt;EnterpriseAccount&lt;/a&gt; can be used as examples, once they are good examples of polymorphism. Throughout the application, some methods use an object BankAccount as a parameter. However, the objects passed to those methods are IndividualAccount or EnterpriseAccount instances, and this only works because of their inheritance relation and polymorphism. Also, we have an example of &lt;strong&gt;compile-time polymorphism&lt;/strong&gt;, once the method &lt;code&gt;isDocumentValid&lt;/code&gt; is overridden in both concrete classes. &lt;/p&gt;

&lt;p&gt;Polymorphism is an effective way to make code flexible, extensible, and easy to maintain, as it allows shared methods across an entire hierarchy of objects.&lt;/p&gt;




&lt;p&gt;In the end, maybe this text became longer than I wanted it to. And I didn't go deeper at any of the four pillars. There is more to talk about and learn. &lt;br&gt;
Also, the application used in the examples is to give you a concrete case of each pillar in a "real" application. When we work in production code, the challenges are more difficult, and the lines between good and bad code are thin. But if you understand these concepts, the path to good decisions may be clear. &lt;br&gt;
I hope you enjoyed it! Thanks.&lt;/p&gt;

&lt;h4&gt;
  
  
  References:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.designgurus.io/blog/object-oriented-programming-oop?gad_source=1&amp;amp;gclid=CjwKCAjw34qzBhBmEiwAOUQcF2f6luJFSwgVuMLHr22LxFvCyiNinrZlQTEHLoa6uTuRyltPyNkCnxoCJnoQAvD_BwE" rel="noopener noreferrer"&gt;Beginner's Guide to Object-Oriented Programming (OOP)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@kalanamalshan98/oop-concepts-mastering-basics-with-real-life-examples-for-easy-understanding-part-1-da5b8fc21036" rel="noopener noreferrer"&gt;OOP Concepts: Mastering Basics with Real-Life Examples for Easy Understanding&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://khalilstemmler.com/articles/object-oriented/programming/4-principles/" rel="noopener noreferrer"&gt;4 Principles of Object-Oriented Programming&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nerd.vision/post/polymorphism-encapsulation-data-abstraction-and-inheritance-in-object-oriented-programming" rel="noopener noreferrer"&gt;Polymorphism, Encapsulation, Data Abstraction and Inheritance in Object-Oriented Programming&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>oop</category>
      <category>softwaredevelopment</category>
      <category>programming</category>
    </item>
    <item>
      <title>Object-Oriented Programming - The Bases</title>
      <dc:creator>Flavio Rozendo</dc:creator>
      <pubDate>Sat, 14 Sep 2024 22:11:14 +0000</pubDate>
      <link>https://dev.to/f_rozendo/object-oriented-programming-the-bases-1b7e</link>
      <guid>https://dev.to/f_rozendo/object-oriented-programming-the-bases-1b7e</guid>
      <description>&lt;p&gt;&lt;strong&gt;Object Oriented Paradigm&lt;/strong&gt;, or &lt;strong&gt;OOP&lt;/strong&gt;, is a programming paradigm used on a large scale in the software industry. A lot of software we use is built in OOP, from social media to business applications. &lt;br&gt;
This paradigm can be loved or hated, depends with who you are talking to. But no one can deny its importance. So, before understand more about OOP, let's talk a bit about programming paradigms.&lt;/p&gt;
&lt;h2&gt;
  
  
  Programming paradigm
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;programming paradigm&lt;/strong&gt; is a set of concepts and principles that define how we deal with and resolve problems. It refers to how a programming language organizes, stores, and manipulates data. Different paradigms may resolve the same problem using a different approach, but all of them can achieve the same objective.&lt;br&gt;
The program paradigms might differ from each other in some aspects, such as the way code is &lt;em&gt;organized&lt;/em&gt;, &lt;em&gt;syntax&lt;/em&gt;, &lt;em&gt;grammar&lt;/em&gt;, and even the way that the &lt;em&gt;execution model works&lt;/em&gt;. They are the outcome of research and studies in computer science, incorporating widely used techniques from earlier practices.&lt;/p&gt;

&lt;p&gt;The main programming paradigms currently are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Object Oriented&lt;/li&gt;
&lt;li&gt;Functional&lt;/li&gt;
&lt;li&gt;Procedural&lt;/li&gt;
&lt;li&gt;Imperative&lt;/li&gt;
&lt;li&gt;Declarative&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A programming language can implement more than one paradigm if they want to. For example, Java and Python work with more than one. However, some languages, such as Haskell, are binding to a specific one.&lt;/p&gt;
&lt;h2&gt;
  
  
  OOP History
&lt;/h2&gt;

&lt;p&gt;Coming back to OOP, it’s difficult to determine a unique starting point. There were references to terms and techniques of OOP back in the &lt;em&gt;1950s&lt;/em&gt; and &lt;em&gt;1960s&lt;/em&gt; when groups of studies at &lt;em&gt;MIT University&lt;/em&gt; already used terms as objects and instances. &lt;strong&gt;SIMULA&lt;/strong&gt; is a programming language developed at that time and used some concepts used nowadays in OOP.&lt;br&gt;
However, the first language considered OOP and used on a large scale was &lt;strong&gt;Smalltalk&lt;/strong&gt;, with its first version launched in the &lt;em&gt;1970s&lt;/em&gt;. The real success of this paradigm only began between the end of the &lt;em&gt;1980s&lt;/em&gt; and the beginning of the &lt;em&gt;1990s&lt;/em&gt;. The launch of C++, a C language with support to OOP, was one of the triggers for this success.&lt;br&gt;
Since then, OOP has been one of the most used paradigms in the world. A set of famous languages support it, such as &lt;em&gt;Java&lt;/em&gt;, &lt;em&gt;C#&lt;/em&gt;, &lt;em&gt;Python&lt;/em&gt;, &lt;em&gt;Javascript&lt;/em&gt;, &lt;em&gt;Kotlin&lt;/em&gt;, and &lt;em&gt;PHP&lt;/em&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  How OOP Works?
&lt;/h2&gt;

&lt;p&gt;OOP is based on &lt;strong&gt;objects&lt;/strong&gt;. But what does this mean? To answer this question, it's common to say that objects represent things from the real world in software. Maybe this is not the best explanation so we will try a different one.&lt;br&gt;
Let's get a bank account as an example. When we open an account, we have some informations about this account, such as agency,  account number, and balance.&lt;br&gt;
We also need to execute some operations, such as withdrawing, depositing money, paying bills, and receiving transfers from other persons.&lt;br&gt;
So in the end, to represent an account, we need a set of &lt;strong&gt;data&lt;/strong&gt; and &lt;strong&gt;behavior&lt;/strong&gt;. And this is exactly what an object is. We can use our object to store the state, such as the account number and balance, and also define how we can manipulate our data and change this state.&lt;br&gt;
In OOP, a computer program is nothing more than a &lt;em&gt;collection of objects&lt;/em&gt;, and the software works from the &lt;em&gt;interaction&lt;/em&gt; between those objects.&lt;br&gt;
This paradigm has a lot of benefits, but in the end, the main objective is to make software that is easy to maintain, change, and grow. Before OOP, some software was too confusing to understand, making any change, even the small ones, very difficult. With objects, we group data that represent something and define the boundaries and rules for those data. With this, we achieve modularity, reusability, scalability, maintainability, and extensibility easier.&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic Concepts
&lt;/h2&gt;

&lt;p&gt;Now, let's go deeper into some technical concepts of OOP. Here I will use some code examples, based on Java language, but that could be adapted easily to any other language that supports OOP. &lt;/p&gt;
&lt;h3&gt;
  
  
  Classes
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Classes&lt;/strong&gt;, or &lt;em&gt;concrete classes&lt;/em&gt;, can be defined as a template for objects. The goal is to create a reusable structure, defining fields and methods, that will be used to create as many objects as it needs. Here is an example of how to create a class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class CodeExample {
    int id;
    String name;

    public void save() {
       //more code
    } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a class, &lt;strong&gt;fields&lt;/strong&gt; are where our object data is stored. Those data also define the state of an object. A class can have as many fields as it wants, without limitations, although a large class is difficult to handle. Fields can also be known as &lt;em&gt;properties&lt;/em&gt; or &lt;em&gt;attributes&lt;/em&gt;.&lt;br&gt;
Otherwise, methods are the behavior side of a class. Methods define how the data of an object can be manipulated, and how an object state can change. As fields, methods don't have any limitations. In some languages, methods are known as &lt;em&gt;functions&lt;/em&gt;.&lt;br&gt;
A class can be extended by another one. This means it inherits all fields and methods and can add its own. In those cases, the class inherited is known as &lt;strong&gt;superclass&lt;/strong&gt; and the class that extends is known as &lt;strong&gt;subclass&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Interfaces
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Interfaces&lt;/strong&gt; are contracts that define a specific behavior, saying what a class must do without saying how it does it. In the interface, we create what is called &lt;em&gt;method definition&lt;/em&gt;, where we set the method name, parameters, and return types, without the implementation.&lt;br&gt;
Once a class implements the interface, it must implement all those methods, following the definition of the interface.&lt;br&gt;
More than one class can implement the same interface. With this, objects of different types can have the same methods, even with a different behavior.&lt;br&gt;
In OOP an interface &lt;strong&gt;can't&lt;/strong&gt; have fields and implement methods, and each class can implement just one interface. However, some languages broke this rule, allowing methods implementation on the interface, and multiple interfaces per class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface OopInterfaceExaple {
    public void someMethod(int parameter);

    public double anotherMethod();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Abstract Classes
&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;abstract class&lt;/strong&gt; is a mix between &lt;em&gt;classes&lt;/em&gt; and &lt;em&gt;interfaces&lt;/em&gt;.&lt;br&gt;
This kind of class can define fields and methods as well. Besides that, as the interfaces, this class can create a &lt;em&gt;method definition&lt;/em&gt; without creating the &lt;em&gt;implementation&lt;/em&gt;. These methods are known as &lt;strong&gt;abstract methods&lt;/strong&gt;.&lt;br&gt;
Because of this behavior, we &lt;em&gt;can't create&lt;/em&gt; an object from an abstract class.&lt;br&gt;
To use an abstract class, we must extend this class with a &lt;em&gt;concrete class&lt;/em&gt;. When we do that, as happens when a class implements an interface, we must define a concrete implementation for all the abstract methods.&lt;br&gt;
We can have an abstract class extending another abstract class. However, we still can't create an object, even if the new abstract class implements all abstract methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public abstract class AbstractExample {
    public abstract int someAbstractMethod(); 

    public long someConcreteMethod(long a, long b) {
        return a + b; 
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Objects
&lt;/h3&gt;

&lt;p&gt;We already discussed what is an object in OOP. But now that we know classes and interfaces, let's talk more, focusing on the technical part.&lt;br&gt;
Objects are &lt;strong&gt;primary components&lt;/strong&gt; of the OOP paradigm. They are instances of a class, which means they are a &lt;em&gt;self-representation&lt;/em&gt; of the class. &lt;br&gt;
We can make a parallel between &lt;em&gt;software&lt;/em&gt; and &lt;em&gt;architecture&lt;/em&gt;. When an architect creates a project, it defines how a house should be built, without building anything. With the project, we can create as many houses as we want. All the houses will have the same base structure but have no relation and can be different in some aspects, such as inside and outside color.&lt;br&gt;
&lt;em&gt;Objects&lt;/em&gt; and &lt;em&gt;classes&lt;/em&gt; work the same. A class defines the fields and methods that the objects will have. With a class, we can create as many objects as we want. Those objects share the same structure, so they all have the same fields and methods. However the state of each object is individual, and they don't share data between them.&lt;br&gt;
We can use the command &lt;em&gt;new&lt;/em&gt; to create a new instance of an object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SomeClass object = new SomeClass();

AnotherClass anotherObject = new AnotherClass(value);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each object will be a set of fields and methods.&lt;/p&gt;

&lt;h4&gt;
  
  
  Fields
&lt;/h4&gt;

&lt;p&gt;As we said more than once, a field keeps the object data and state. However not all the fields are the same, and they can hold different types of information. This can be different from language to language, but some types exist in almost all of them: int, float, double, char, and boolean.&lt;br&gt;
Each type of field can hold a specific information. For example, int fields are for integer numbers, and boolean stores &lt;em&gt;true&lt;/em&gt; or &lt;em&gt;false&lt;/em&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Methods
&lt;/h4&gt;

&lt;p&gt;Methods is where the action of an OOP application happens. Besides the possibility of changing the state of an object and manipulating their data, they also can call other objects, as long as they have an instance of this object they want to call.&lt;br&gt;
A method can have parameters, which are values received when this method is called. There are no limits to how many parameters a method has, but the more they have, the harder it is to interact with them.&lt;br&gt;
They can return a value as the result of its operation. Usually, a method can return only one type of value, but some languages allow the return of different types, and some more than one return at once.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;someObject.makeSum(10, 5); 

someObject.printMessage("Hello OOP");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  More concepts
&lt;/h2&gt;

&lt;p&gt;Besides classes and objects, there are other important concepts to know before the next step. &lt;/p&gt;

&lt;h3&gt;
  
  
  Constructors
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Constructors&lt;/strong&gt; are special methods called when the object is created. They are used with the &lt;em&gt;new&lt;/em&gt; keyword and called only once in the object lifecycle. &lt;br&gt;
We use this method to set up the object on its creation, ensuring its state before using it.&lt;br&gt;
We can have parameters on constructors, and some languages allow a class to have more than one. When this happens, each version must distinct on the number of parameters, or they should have different types.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class SomeClass() {

    public SomeClass() {
        //init object state
    }

    public SomeClass(int value) {
        //init object state
    }

    public SomeClass(String message) {
        //init object state
    }

    public SomeClass(int value, String message) {
        //init object state
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Destructors
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Destructors&lt;/strong&gt; are also a special method but are the opposite of constructors. This method is called before the object is destroyed. As constructors, they are called automatically and only once on the object lifecycle.&lt;br&gt;
With this method, we can perform cleanups and release resources used, such as memory, files, and network connections.&lt;br&gt;
Not all languages implement this kind of method. Some languages work with &lt;em&gt;garbage collectors&lt;/em&gt; to release resources instead of destructors.&lt;/p&gt;
&lt;h3&gt;
  
  
  Access Modifiers
&lt;/h3&gt;

&lt;p&gt;Although the basics of any OOP application are the communication between objects, it's not desirable to allow full access to all methods and fields of any object. Sometimes we want to hide some fields and methods and allow access to only a set of objects, or even hide everything.&lt;br&gt;
This behavior can be achieved with &lt;strong&gt;access modifiers&lt;/strong&gt;. They can define the level of visibility of classes, methods, and fields. This way, we can control what we expose, how the state of an object can change, and who can change this state.&lt;br&gt;
Again, this can be different from language to language, both in behavior and in existing types, but basically, there are four types of access modifiers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;public:&lt;/strong&gt; there are no restrictions on access, fields or methods are accessible from anywhere.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;private:&lt;/strong&gt; allows access only inside the class where the method or field is defined, so they cannot be accessed directly from outside the class.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;protected:&lt;/strong&gt; members protected are accessible within the class in which they are defined and by subclasses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;default:&lt;/strong&gt; some languages have default access if no modifier is provided, and the access is allowed just in the same package or something analog to this (namespace, assembly).
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class ExampleClass {

    private int someValue;

    public ExampleClass(int value) {
        int someValue = value;
    }

    protected int giveMeResult(int anotherValue) {
        return someValue + anotherValue;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Overloading
&lt;/h3&gt;

&lt;p&gt;Sometimes we need to do the same thing in different ways. In OOP we can do this using a technique called &lt;strong&gt;overloading&lt;/strong&gt;.&lt;br&gt;
Overloading allows us to have more than one version of the same method. In this case, we consider the same when the method name and the return type are the same. In overloading, we must have different parameters, either type or quantity, for each version of the method.&lt;br&gt;
For example, we can create a &lt;code&gt;printNumber&lt;/code&gt; method that takes an int value and prints it on the screen. We can also have another version that takes a long value. It's also possible to have a version that receives an int and a long, sum them, and print on the screen. The only thing different between all versions is the parameter types.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void printNumber(int value) {
   //print the number
}

public void printNumber(long longValue) {
   //print the number
}

public void printNumber(int value, long longValue) {
   long result = value + longValue;
   //print the number
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Overloading can be done in the same class, but a subclass can overload a superclass's method.&lt;/p&gt;

&lt;h3&gt;
  
  
  Override
&lt;/h3&gt;

&lt;p&gt;Unlike overloading, &lt;strong&gt;override&lt;/strong&gt; is when we change a method behavior, without changing the definition.&lt;br&gt;
A &lt;em&gt;subclass&lt;/em&gt; can override a &lt;em&gt;superclass&lt;/em&gt; method, creating a method with the same name, parameters, and return type. This way, the subclass can change the behavior to its needs.&lt;br&gt;
It's possible to completely override the method, or include his behavior, and then call the original method of the superclass, taking advantage of what exists there.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class SuperExample {
    public void someMethod(long value) {
        //super class behavior
    }
}

public class SubExample extends SuperExample {
    @Override
    public void someMethod(long value) {
        //sub class behavior
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;These are some basic characteristics of OOP paradigms, and there was already a lot to talk about. However, we will save the best for another post: the main pillars of OOP. &lt;br&gt;
See you soon! Thanks!&lt;/p&gt;

&lt;h4&gt;
  
  
  References:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.designgurus.io/blog/object-oriented-programming-oop?gad_source=1&amp;amp;gclid=CjwKCAjw34qzBhBmEiwAOUQcF2f6luJFSwgVuMLHr22LxFvCyiNinrZlQTEHLoa6uTuRyltPyNkCnxoCJnoQAvD_BwE" rel="noopener noreferrer"&gt;Beginner's Guide to Object-Oriented Programming (OOP)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Object-oriented_programming" rel="noopener noreferrer"&gt;Object-oriented programming&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.oreilly.com/library/view/beginning-c-30/9780470261293/9780470261293_a_short_history_of_object-oriented_progr.html" rel="noopener noreferrer"&gt;1.1. A Short History of Object-Oriented Programming (OOP)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/benefits-advantages-of-oop/" rel="noopener noreferrer"&gt;Advantages and Disadvantages of OOP&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/object-oriented-programming-oops-concept-in-java/" rel="noopener noreferrer"&gt;Object Oriented Programming (OOPs) Concept in Java&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.freecodecamp.org/news/object-oriented-programming-basics-oop-classes-and-objects-in-java/" rel="noopener noreferrer"&gt;Object Oriented Programming Basics – OOP, Classes, and Objects in Java&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.freecodecamp.org/news/an-introduction-to-programming-paradigms/" rel="noopener noreferrer"&gt;Programming Paradigms – Paradigm Examples for Beginners&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@Ariobarxan/what-is-a-programming-paradigm-ec6c5879952b" rel="noopener noreferrer"&gt;What is a programming paradigm?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>oop</category>
      <category>programming</category>
      <category>softwaredevelopment</category>
    </item>
  </channel>
</rss>
