Skip to content

Instantly share code, notes, and snippets.

@htdangkhoa
Last active April 21, 2022 07:32
Show Gist options
  • Save htdangkhoa/4602482121553989c269dd64ef015194 to your computer and use it in GitHub Desktop.
Save htdangkhoa/4602482121553989c269dd64ef015194 to your computer and use it in GitHub Desktop.
import { AbstractFactory } from './AbstractFactory';
import { ConcreteFactory1, ConcreteFactory2 } from './ConcreteFactory'
function clientCode(factory: AbstractFactory) {
const productA = factory.createProductA();
const productB = factory.createProductB();
console.log(productA.usefulFunctionA());
console.log(productB.usefulFunctionB());
}
console.log("Client: Testing client code with ConcreteFactory1");
clientCode(new ConcreteFactory1());
console.log("----------------");
console.log("Client: Testing the same client code with ConcreteFactory2");
clientCode(new ConcreteFactory2());
/*
Output:
Client: Testing client code with ConcreteFactory1
The result of the product A1.
The result of the product B1.
----------------
Client: Testing the same client code with ConcreteFactory2
The result of the product A2.
The result of the product B2.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment