Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

ts Facade pattern

/*Facade
The Facade pattern is a design pattern lets you define a simple unified interface 
to a large body of code .

imagine you want to make a car and you want to make it with a engine, 
transmission, and wheels.

First you need to make a car class:
*/
class Car {
  public makeCar() {
    console.log('Making a car...');
  }
}

// Then you make a facade class that will make the car with an engine, transmission, and wheels and abstract the process from the user
class CarFacade {
  constructor(private car: Car) {}

  public makeCar() {
    this.car.makeCar();
    this.makeEngine();
    this.makeTransmission();
    this.makeWheels();
  }

  private makeEngine() {
    console.log('Making engine...');
  }

  private makeTransmission() {
    console.log('Making transmission...');
  }

  private makeWheels() {
    console.log('Making wheels...');
  }
}

// Then you make your car:
const car = new CarFacade(new Car());
car.makeCar();
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #ts #Facade #pattern
ADD COMMENT
Topic
Name
2+8 =