<?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>Forem: Bruno Santos</title>
    <description>The latest articles on Forem by Bruno Santos (@bruno34154).</description>
    <link>https://forem.com/bruno34154</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%2F1056700%2Fb968bfc1-988a-4ccc-bab5-af26a7c3de8d.jpeg</url>
      <title>Forem: Bruno Santos</title>
      <link>https://forem.com/bruno34154</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/bruno34154"/>
    <language>en</language>
    <item>
      <title>How I Broke 13 Endpoints and Learned the Hard Way About SOLID’s Open/Closed Principle</title>
      <dc:creator>Bruno Santos</dc:creator>
      <pubDate>Wed, 16 Jul 2025 20:34:33 +0000</pubDate>
      <link>https://forem.com/bruno34154/how-i-broke-13-endpoints-and-learned-the-hard-way-about-solids-openclosed-principle-1oa4</link>
      <guid>https://forem.com/bruno34154/how-i-broke-13-endpoints-and-learned-the-hard-way-about-solids-openclosed-principle-1oa4</guid>
      <description>&lt;p&gt;As developers, we often take our systems for granted. We build, we test, and sometimes, we break things. I recently found myself in a situation where I broke not just one, but 13 endpoints, and the reason? A simple violation of a core principle of object-oriented design: the Open/Closed Principle (OCP), one of the five principles that make up SOLID.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is SOLID?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before I dive into how I learned about the importance of OCP, let’s briefly go over what SOLID stands for:&lt;/p&gt;

&lt;p&gt;S: Single Responsibility Principle (SRP)&lt;/p&gt;

&lt;p&gt;O: Open/Closed Principle (OCP)&lt;/p&gt;

&lt;p&gt;L: Liskov Substitution Principle (LSP)&lt;/p&gt;

&lt;p&gt;I: Interface Segregation Principle (ISP)&lt;/p&gt;

&lt;p&gt;D: Dependency Inversion Principle (DIP)&lt;/p&gt;

&lt;p&gt;Each principle is a guideline that helps developers design software that is easier to maintain, extend, and scale. But one principle stood out during my recent experience: the Open/Closed Principle.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Understanding Open/Closed Principle&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The Open/Closed Principle states that software entities (classes, modules, functions, etc.) should be open for extension but closed for modification. In other words, you should be able to add new functionality to a system without changing the existing code.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why is this important?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;If we don't respect this principle, we risk introducing errors into areas of the code that were previously working fine. Imagine a situation where you're working with a function that is referenced in multiple parts of your system—what happens if you change its behavior or return value? If those references expect the function to behave in a certain way, you can easily break the whole system.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;My Experience&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;: The Case of the Broken 13 Endpoints&lt;br&gt;
I was working on a system with several endpoints that relied heavily on a function to return specific data. One day, I was tasked with making a change to the return value of this function. It seemed like a simple fix—one change to improve the code.&lt;/p&gt;

&lt;p&gt;However, I didn't stop to think about the impact this would have. This function was referenced in 13 different places across various endpoints. Without considering the OCP, I modified the function's return structure, assuming it wouldn't cause any issues.&lt;/p&gt;

&lt;p&gt;What happened next was a mess: 13 endpoints stopped working. Each endpoint relied on the previous behavior of that function, and by changing its return value, I broke the contract that these endpoints were built on. This mistake cost a lot of time to fix and even affected the overall system stability.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How OCP Could Have Saved Me&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Had I adhered to the Open/Closed Principle, the change would have been different. Instead of modifying the function's return type directly, I could have extended the function’s behavior—keeping the original functionality intact while adding the new behavior in a way that didn’t affect the existing system.&lt;/p&gt;

&lt;p&gt;In practice, I could have:&lt;/p&gt;

&lt;p&gt;Created a new method to handle the new behavior.&lt;/p&gt;

&lt;p&gt;Used polymorphism to extend the functionality.&lt;/p&gt;

&lt;p&gt;Made use of strategy or decorator patterns to change the behavior dynamically without breaking existing code.&lt;/p&gt;

&lt;p&gt;The key takeaway here is that by thinking through the principle of open for extension, closed for modification, I could have avoided the huge impact that this change had.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;Learn From My Mistake&lt;br&gt;
In the end, this was a painful but valuable lesson. It reinforced the importance of defending your code by respecting principles like OCP. By keeping systems open for extension and closed for modification, you avoid unintentionally breaking things that other parts of the system depend on. Always think about the bigger picture before making changes that might seem small at the time.&lt;/p&gt;

&lt;p&gt;So, to all the developers out there—don’t be like me. Respect the Open/Closed Principle. It will save you from breaking everything when you least expect it!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The awesome layered architecture</title>
      <dc:creator>Bruno Santos</dc:creator>
      <pubDate>Wed, 05 Apr 2023 07:31:36 +0000</pubDate>
      <link>https://forem.com/bruno34154/the-awesome-layered-architecthure-3leo</link>
      <guid>https://forem.com/bruno34154/the-awesome-layered-architecthure-3leo</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hey Friends! Today i going to talk about a thing i'm learning in this latest times in a project that i'm working, that's the software architecture, it's funny because we don't care so much about this thing in the beginning and in fact it's useless when we are working with a simple personal projects, because we don't write so much code for lose ourselfs reading some files yet, but when us started to come into in a real project that has a bunch of funcionalities and code we finnally get it the meaning of all this... If the team doens't have in mind the architecture of the project, it really can to cause "headaches" in the future.&lt;/p&gt;

&lt;p&gt;In that project that i recently started to work, we are going through this, we are working with Laravel in a big project, for standard everyone knows that technology works with MVC right?&lt;br&gt;
A quick explans about what's MVC:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WR_2EvSQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mmfvncvpevdpfqb2zrxt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WR_2EvSQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mmfvncvpevdpfqb2zrxt.png" alt="Mvc" width="576" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The "Problem" with MVC&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;M- means model that's for working with the database, here we create tables, write and validate any data in database.&lt;br&gt;
V- means view your responsibily is show the user the informations in the application and allow he to interact with our app,&lt;br&gt;
C - means controller that's responsible for receive the requests, doing the validations, operating the bussiness rules, controling the model, and  sending a responsive to view.&lt;/p&gt;

&lt;p&gt;MVC is already really good for organize your code right? But in this explanantion about this architeture, we can realize there's a side is still with a lot of work, and yes the controller is the problem here, because it's with a bunch of responsabilities, because he's the "center" of everything here, and this results in giants controllers that how more we have functions more unreadble the code there becomes, for example in the project that i'm working we have (believe in me i'm not kidding!) controllers with more of 1000 LINES!! This is crazy right? So how we can solve this problem? It's in this scenario that was create the layered architecture, the solution for the controller's problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What's Layered Architecture?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I think the layered architecture like a evolution of MVC because it simplely takes the controller that's the problem in this architecture and split it in more two layers that are called repository and service, in other words we had only 1 layer for this responsability and now we have three layers!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OIFxIogx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/poxewoid638ul2ibbx7l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OIFxIogx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/poxewoid638ul2ibbx7l.png" alt="Image description" width="820" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Repository: it's responsible for managing the model in database  search, delete and store data.&lt;/p&gt;

&lt;p&gt;Service: it's responsible for doing the business logic, all the validations and manipulations with the data from repository stay here.&lt;/p&gt;

&lt;p&gt;Controller: in this pattern the controller is only responsible for receiving the request and sending a response for the view.&lt;/p&gt;

&lt;p&gt;Using layered architure means less code in the controller and now the controller don't need to know the database and manipulate the data, it's easier for testing the backend beacause if you are receiving a bad response from controller you don't have to search in 1000 lines of code to discover where the problem is. If the problem is in the request you can find the error in the controller, if the problem is in the validation search in the service, if the server isn't saving in the database probably search for the bug in repository is the best solution, briefly you going to have less headache for solve your bugs, although it's much easier to updating your backend because you won't have repetitive code for save in a table from  your database in every function that you need it in controller for example, instead that you simple can call a function in repository, here goes a quick use case:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Puting dogs in the database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this example we going to store dogs in our database for example, first the user send a request to store a dog called Rex, first we receive the data by rquest in our controller's function, the controller takes thia request, we take the $request-&amp;gt;name and put it in the parameter for the function dogsService-&amp;gt;store() here we are calling the service in the controller, where we receiving thos parameter and doing the validation, we verify if already exists the same dog in the database, if the name is correct, etc.. and if everything is fine we pass this data to the function dogsRepositoritory&amp;gt;store(), where we going to call the table dogs in database and use the ORM to store the data there.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this articles we see the importance of a good architecture like the layered architecture, it's really important for improve the aplicattion's performance, i hope you enjoy the article.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>architecture</category>
      <category>designpatterns</category>
      <category>laravel</category>
    </item>
  </channel>
</rss>
