3 Jun
Neal Ford: Design Patterns in Ruby
The room is crowded, steady the riddle appears the book “Design Patterns (the gang of four)’, in this main division, Neal says that in that place are not only references end also valid examples (even if they are not expressed in Ruby)
There are sum of two units destinct problems Neal confirms, the patterns in theor theoretical exceptions and their implementation. The dynamic languages have a big advantage which time it income impementing patterns in substantial cases.
Iterator Pattern:
Neal does not appreciate this original very much: little tecnical for the technical people and too technical for the non technical people. The pattern provides the ability to access in sequence an array of elements.
Neal asks: what do we need these patterns for compared to a normal iterator .each? in reality even any iterator each apply to a iterator copy (internal).
Instead the external iterator is a version of this pattern implemented, for example in the cycle for.
Command Patterns:
The command pattern is implemented in Ruby end the blocks. Each block incapsulates a command. In reality this comparison is not 100% trusty, it will require some modifications to be made to tie in the command pattern to a block.
Strategy Pattern:
This pattern defines a set of algorithms, incapsulates them and makes them interchangeable. It is implemented in traditional ruby with a module that defines an empty function that is overwritten one at a time form the classes that it includes it.
But what will happen if the method in proposition is maybe “call” (the combination between the strategy and the enjoin pattern)? Each algorithm will have existence incapsulated in a block and the array of this fill up shall be implemented from the strategy pattern.
Another possible implementation: to make it in a way that a class extends not the same dynamically. (choosing which classes should extend instances in question in a way assigned like this methods are diverse to the classes)
Interpreter Pattern:
Supply an interpreter to grammer to interpret a specific speech. (JRuby in the place of example is an example of the application in this pattern) With this pattern it is possible to construct DSL (domain specific languages). With Ruby it is very yielding to construct DSL in virtue from its flexible syntax.
Adapter Pattern:
Convert an interface into another. The implementation standards in ruby, gives you two classes (round and square), to create a third that in some way transforms the instance of the destination; recipient of the rank A into an object of the class B.
We can dynamically create methods of instances for the instance that we want to modify. But what will take place if in this way we create a conflict of methods? We can dynamically modify the names of the methods to make it in a way that they don’t overwrite the result, then creating a kind of selector to specify each time which method we absence to call betwixt those that are available.
Sate Pattern:
Changing the class of the instance to take order of importance a particular event. To implement this pattern we can utilize mixology, a gem that consents us to perform a mixing of modules.
Null Object Pattern:
Utilize any object that impersonates the Null concept. This exemplar doesn’t exist in Ruby. It exists directly in the class language that is called NilClass.
Aridifier Pattern:
It is a pattern that is derived from the book “Programmatic Programmers” that aims to execute the language more arid, in how much according to the author a language is more arid is for its nature more secure.
Conclusioni:
Neal concludes stating that Patterns are not anything but solutions strong for a common problem.
Annalisa
