Design Patterns in Ruby (Addison-Wesley Professional Ruby Series)
Rate it:
Open Preview
Kindle Notes & Highlights
70%
Flag icon
operate. In this chapter, we will explore the Domain-Specific Language (DSL) pattern, which looks at the world from the other end of the telescope. The DSL pattern suggests that you should focus on the language itself, not on the interpreter.
70%
Flag icon
DSLs. External DSLs are external in the sense that there is a parser and an interpreter for the DSL,
70%
Flag icon
An internal DSL, again according to Fowler, is one in which we start with some implementation language, perhaps Ruby, and we simply bend that one language into being our DSL. If we are using Ruby to implement our DSL—
73%
Flag icon
Finally, if security is an issue, stay away from internal DSLs—far, far away. After all, the whole point of an internal DSL is that you take some arbitrary code that someone else wrote and suck it into your program. That requires a toothbrush-sharing level of trust.
74%
Flag icon
This custom-tailoring technique is particularly useful when you have lots of orthogonal features that you need to assemble into a single object. By simply manufacturing an object to specification, you can avoid creating a whole host of classes with names like WoodyStemmedNeedleLeafFloweringPlant and VinyStemmedBroadLeafNonfloweringPlant.
74%
Flag icon
Sometimes the best way to approach a task like this one is to imagine what we want the end result to look like and then work backward to an implementation.
77%
Flag icon
While the other patterns mostly dealt on the smaller scale of pulling together a number of related classes, Convention Over Configuration is concerned with pulling together whole applications and application frameworks.
78%
Flag icon
Name your adapter class <protocol>Adapter.
79%
Flag icon
Name your adapter class <protocol>Adapter and put it in the adapter directory.
80%
Flag icon
one of the principles of good interface design is to provide the user with templates and samples to help get started. At one end of the spectrum, we might provide a few examples showing how to create a protocol adapter or an authorizer. At the other end of the spectrum, we could supply a utility to generate the outline or scaffold of a class.
80%
Flag icon
Another potential source of trouble is the possibility that a system that uses a lot of conventions may seem like it is operating by magic to the new user.
81%
Flag icon
But as we work our way through the new wisdom gap, we will uncover even more solutions, new design patterns that will fit the dynamic, flexible world of Ruby. I don’t know what those new patterns will look like, but I do know that I can’t wait to see them. I also know that it is a great time to be a programmer.
« Prev 1 2 Next »