Let's have a talk about: Design Patterns

Let's have a talk about: Design Patterns

In the Software Engineering world exists many principles which guides the practice. These principles build the stones of our work and the great companies such as Microsoft and Google have been using a lot of them in their own solutions including in the .NET platform and in the Angular framework.?

One of these principles that I have learned in my journey as a developer is about Design Patterns, a very important topic that helps us being more effective while we are building solutions using the Oriented-Object paradigm and trying to avoid bugs.

What are Design Patterns?

Design Patterns are well know and tested solutions for recurrent problems that many developers face everyday. They remove the need of reinventing the wheel providing a clear structure that we can reuse and adapt to our context and helps us to accomodate business rules in our software architecture.

Some experience using Design Patterns has made me see the benefits of it, such as:

  1. help a team to be more productive while writing flexible, reusable and easy to maintain code;
  2. share a common vocabulary that accelerates the communication inside a team;
  3. accelerate the implementation of new customer requirements;
  4. reduce the amount of bugs and improve quality of the code;
  5. incentivate new developers to learn about these patterns expanding their habilities and knowledge;
  6. reduce conflicts using version controls (such as GIT) once we can strategize a way of how any develop works in a separated part of the system, e.g, using Strategy pattern for separating different kinds of behavior in an application.

There are different Design Patterns but the greatest contribution was made by Gang of Four, a group of 4 engineers who has catalogued 23 Design Patterns in a book called Design Patterns: Elements of Reusable Object-Oriented Software, separating the patterns in 3 different categories: creational, behavioral and structural.

In my opinion these patterns should be understandable for anyone who desires to build more sophisticated solutions and used for improving the way how the software can change in the future for attending new customer requirements that can arrives, with the capacity to evolve and scale more easily.

The Strategy, e.g, groups a family of alghorithms under an interface allowing us to exchange the code behavior in runtime and organize the code in a better and readable form. We could use it to calculate different types of loans on a bank or insurance application simulation.

Observer creates a relationship between one and many objects on the system and notify all the objects when a change happens. This is very useful to send messages such as push notifications and for triggering events.

The Decorator helps us to implement the Open Closed Principle of SOLID wich says that a class should be open to extension but closed for modifications. We can use it to extend behaviors, very usefull in a payment system where we should calculate prices of some products, where new values that originally do not belongs to the product can be added in the future, including rate and shipping costs.

Factory method is a good alternative for helping us to instantiate classes passing some additional configuration in their creation, desacoupling our code and helping it to be testable.

Also there are other patterns, besides the 23 who has catalogued by GoF, such as Dependency Injection and Repository Pattern and many many others. With the first we are able to provide instances (dependencies) of a class in an external way, reducing the coupling of a system and building more flexible solutions. The second helps us to abstract the way that we access the database, isolating the business code from data access code and facilitaing the queries and other operations that we need to do while retrieving and writing data on a database (CRUD operations).

If you are not familiar with Patterns I invite you to read the GoF and Freeman's book which is very nice. Microsoft also has a series about Design Patterns where the experts Robert and Phil teach us about some of them. There are web sites at the network as Refactoring Guru that are good places with good examples too. And in a next talk we should speak about Patterns of Enterprise Application Architecture provided by Fowler on his book! It's like an explosion of many kinds of patterns for architecture that we can learn and use in our projects.

There a lot of benefits in using Design Patterns and they can improve the quality of a system development and also the speed of implementing new features. I've already saw and participated of one situation where my team and I were able to reduce a time of 1 week for 2 days while programming some User Stories, thanks to the good use of Design Patterns solutions that made possible reduce the amount of lines of code that we were writing. It was a combination of different kinds of patterns inside the same solution to solve a real problem.

There are situations where we can see a perfect scenario inside the code where a Design Pattern fits very well and when it happens is like magic!

My point is that any develop should try to learn and use some of the Design Patterns because I really believe it can help to achieve better results and maximize the value of the software that can be delivered for production, reducing bugs, facilitating it's evolution on the future and making a team more efficient.

Thank you for reading so far! See you the next time!

要查看或添加评论,请登录

Lu? Falc?o的更多文章

社区洞察

其他会员也浏览了