jueves, 20 de octubre de 2016

Patterns. Software patterns everywhere…

Ummm what?
I didn’t know what these were, either. After some research, I’ll now try explaining to you what I learned. Sounds good to you?

Again, this has a very continuous relationship with previous topics I’ve talked about before. Specially, you’ll find yourself thinking of software architecture (hopefully). Why? For starters, design patterns are something a software architect should always be able to identify. Let me too you why…

There are some reusable, optimized solutions to common programming problems. Solutions that people who build programming languages should also identify right away. This solutions I’m talking about are, in fact, design patterns. But all these people must be careful: “If implemented in the wrong place, it can be disastrous and create many problems for you. However, implemented in the right place, at the right time, it can be your savior”. (source)

It’s important to know there are basically 3 types of design patterns:
  • Structural
  • Creational
  • Behavioral
Their names don’t say much, do they?

Structural patterns refer to relationships, how entities work together.
Creational patterns refer to the way mechanisms are instantiated, so each situation has its easiest way of object-creation.
Behavioral patterns refer to the communication between entities (please do not confuse these with structural patterns).

What I mean by “patterns” is basically past situations other programmers have been through. They’ve experienced the same, and now they know a solution for it. Why wouldn’t you want to consider their way of solving these problems?

Let me include a very illustrative result:


Imagine something like this in code-form. How many interfaces do you see? several.
But on the other side, in how many ways is this thing reacting to the several interfaces? One. Just one! This is precisely one example of the adapter pattern: “structural design pattern that allows you to repurpose a class with a different interface, allowing it to be used by a system which uses different calling methods”. How COOL is that?

This one and some other examples can be found here: https://code.tutsplus.com/articles/a-beginners-guide-to-design-patterns--net-12752

One last thing before you go: ALWAYS make sure the solution you’re working with is actually meant for particular problems like your own. Hopefully you won’t ever find yourself in a situation where you learn this the hard way.


1 comentario: