Articles about
Design Patterns
So, our little exercise in design patterns is getting quite messy. Which is ironic, considering it’s an exercise in design patterns.
The reason is that I’m mostly trying to be very focused on the Design Patterns book and just fleshing out the example implementations they provide.
Therefore, in order to organize things, I believe this is the right time to add unit tests. As a plus, I also get to test my little gem in an automated fashion.
Here I’ll only go through the RandomMazeBuilder
class since it would be quite lengthy to go through every single file. To see all the other specs, just checkout the repo.
Read more »
In the last part of this series, we left our little maze game gem generating random mazes that had random kinds of rooms using the abstract factory pattern.
While that was good enough, in the case of the our maze game, it turns out mazes can be pretty complex objects, being a collection of rooms, doors and walls of many types. And even though I didn’t add too much variety of these components, things could get pretty convoluted.
It turns out there’s a pattern just for these cases: the Builder Pattern.
Read more »
The title says it all, but how does one actually implement object oriented design patterns in Ruby? If you’re like me and always struggled with putting what you read about programming into an actual implementation and the examples in the book or around the internet weren’t enough to quell your doubts, read on.
Read more »
In this series of code refactoring posts we are discussing how design patterns can be used to make our Ruby code beautiful, maintainable and clean.
Today I want to talk about a pattern that can be very useful when we need to control the flow of a set of events of our objects: The State Pattern a.k.a Finite State Machine.
As a developer it is common to see objects changing their state. At the beginning managing the state of an object can be as simple as having some boolean attributes where you can check if the object is in state A or B. But when the complexity increases you can end up with a number of states that are difficult to manage without breaking the SOLID principles. That is where we can implement the elegant solution provided by the State Pattern.
Read more »
In our last article of the refactoring series we saw how design patterns can be used to make our Ruby code beautiful and clean. Design patterns are a powerful tool for any developer and a familiarity with them will lead to better code by forcing a consideration of SOLID principles.
Now let’s talk about other pattern that when properly used can be very helpful: The Template Method.
Read more »