sdfxs

Untitled

May 11th, 2021
608
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. enum Model {
  2.     Sport,
  3.     Mini
  4. }
  5.  
  6. class Car {
  7.     private model: Model;
  8.     private price: number;
  9.     private maxSpeed: number;
  10.  
  11.     constructor(model: Model, price: number, maxSpeed: number) {
  12.         this.model = model;
  13.         this.price = price;
  14.         this.maxSpeed = maxSpeed;
  15.     }
  16. }
  17.  
  18. class CarFactory {
  19.     create(type: Model): Car | void  {
  20.         switch(type) {
  21.             case Model.Sport: return new Car(type, 108000, 300);
  22.             case Model.Mini: return new Car(type, 11000, 120);
  23.             default: break;
  24.         }
  25.     }
  26. }
  27.  
  28. const factory = new CarFactory();
  29.  
  30. const sportCar = factory.create(Model.Sport);
  31. console.log(sportCar)
RAW Paste Data