The Adapter: Bridging the Analog Chasm
Convert the interface of a class into another interface clients expect.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Adapter
ARCANUM SCHOOL: Transmutation // Integration
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
public interface GNOMEArtifice.CyberInterface : Object {
public abstract void jack_in(string terminal_id);
}
// The legacy class we want to adapt
public class GNOMEArtifice.AnalogDialup : Object {
public void connect_modem(int baud_rate, string number) {
print(@"Dialing $(number) at $(baud_rate) baud... \n");
}
}
// The Adapter
public class GNOMEArtifice.DialupAdapter : Object, CyberInterface {
private AnalogDialup legacy_system;
public DialupAdapter(AnalogDialup legacy_system) {
this.legacy_system = legacy_system;
}
public void jack_in(string terminal_id) {
print(@"Adapting cyber-jack request to analog lines for $(terminal_id).\n");
this.legacy_system.connect_modem(9600, terminal_id);
}
}
Not all artifacts in the GNOME architecture are built with cutting-edge cybernetics. Often, a technomancer must interface sleek, modern runic structures with crumbling analog dial-ups from a bygone age. The Adapter pattern translates the incantations. It wraps the archaic object, translating the standard jack_in method into the specific pulse-and-tone dialing required by the ancient hardware, bridging the chasm without modifying the sacred old code.
Runic Tags:
#Vala
#GObject
#Structural
#Adapter