SlideShare a Scribd company logo
Object Oriented Imposters
The Adapter Pattern
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.
Encrypter Example
Implement the Encrypter Class
StringIOAdapter
Using our Adapter
Renderer Example
TextObject
BritishTextObject
BritishTextObjectAdapter
Modify a Class on the Fly
Modify a Single Instance
Modify a Single Instance
When to Adapt or Modify
When modifications are simple and clear
You understand the class you’re modifying
and the way in which it is used.
The interface mismatch is really complex.
You have no idea how the class works.
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”
Wrap Up
Adapters are part of the “Object Oriented
Impostor” patterns.
Not just about code, intent is critical.

More Related Content

PDF
Max Dynamic Capability
PDF
The Adapter Pattern in PHP
PPT
Design patterns - Adapter Pattern
ZIP
Adapter Design Pattern
PPTX
Adapter Design Pattern
PPTX
Implementing the Adapter Design Pattern
PPTX
Design Patern::Adaptor pattern
ODP
Design Patterns
Max Dynamic Capability
The Adapter Pattern in PHP
Design patterns - Adapter Pattern
Adapter Design Pattern
Adapter Design Pattern
Implementing the Adapter Design Pattern
Design Patern::Adaptor pattern
Design Patterns

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
cuic standard and advanced reporting.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
20250228 LYD VKU AI Blended-Learning.pptx
Encapsulation theory and applications.pdf
Understanding_Digital_Forensics_Presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Unlocking AI with Model Context Protocol (MCP)
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
The AUB Centre for AI in Media Proposal.docx
cuic standard and advanced reporting.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Advanced methodologies resolving dimensionality complications for autism neur...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Building Integrated photovoltaic BIPV_UPV.pdf
Network Security Unit 5.pdf for BCA BBA.
Reach Out and Touch Someone: Haptics and Empathic Computing
Per capita expenditure prediction using model stacking based on satellite ima...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Ad
Ad

Object Oriented Impostor - Adapter Pattern