Skip to content

Instantly share code, notes, and snippets.

@edubskiy
Created July 4, 2023 15:06
Show Gist options
  • Save edubskiy/86c679254f98f350c06d390b24fe4cdf to your computer and use it in GitHub Desktop.
Save edubskiy/86c679254f98f350c06d390b24fe4cdf to your computer and use it in GitHub Desktop.
Typescript Adapter pattern Implementation and Demo
namespace AdapterPattern {
export class Adaptee {
public method(): void {
console.log("`method` of Adaptee is being called");
}
}
export interface Target {
call(): void;
}
export class Adapter implements Target {
public call(): void {
console.log("Adapter's `call` method is being called");
var adaptee: Adaptee = new Adaptee();
adaptee.method();
}
}
}
// --------------- DEMO ----------------- //
namespace AdapterPattern {
export namespace Demo {
export function show() : void {
var adapter: AdapterPattern.Adapter = new AdapterPattern.Adapter();
adapter.call();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment