The document discusses the adapter pattern in Ruby, which allows objects to bridge interfaces by modifying classes and objects at runtime. It provides examples of using an adapter to encrypt data and modify text objects to different formats. The key points covered are when to use an adapter versus modifying a class directly, with adapters preserving encapsulation but adding complexity, while modifying classes may simplify code at the cost of changing internal workings.
2. Adapters in Ruby
An adapter is an object that bridges the
interface you have and the interface you need
Ruby lets us modify objects and classes
on the fly at runtime.
14. When to Adapt or Modify
When modifications are simple and clear
You understand the class youre modifying
and the way in which it is used.
The interface mismatch is really complex.
You have no idea how the class works.
15. When to Adapt or Modify
Adapters preserve encapsulation at the cost of
some complexity. Modifying a class may buy
you some simplification, but at the cost
tinkering with the plumbing
16. Wrap Up
Adapters are part of the Object Oriented
Impostor patterns.
Not just about code, intent is critical.