Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

facade design pattern typescript

interface Store {
  product(name: string): string
  category(): string
}

class Minuman implements Store {
   product(name: string): string {
      return name
   }
   
   category(): string {
      return 'minuman'
   }
}

class Makanan implements Store {   
   product(name: string): string {
      return name
   }
   
   category(): string {
     return 'makanan'
   }
}

class StoreFaced {
  public minuman: InstanceType<typeof Minuman>
  public makanan: InstanceType<typeof Makanan>
  
  constructor() {
    this.minuman = new Minuman()
    this.makanan = new Makanan()
  }
  
  storeMinuman(name: string): string {
    return this.minuman.product(name)
  }
  
  storeMakanan(name: string): string {
    return this.makanan.product(name)
  }
}

const res = new StoreFaced()
console.log(`product name: ${res.storeMinuman("cola cola")} and product category ${res.minuman.category()}`)
console.log(`product name: ${res.storeMakanan("biskuat")} and product category ${res.makanan.category()}`)
Comment

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();
Comment

ts Facade pattern

/*Proxy
The Proxy design pattern is a design pattern lets you provide a surrogate 
or placeholder object for another object to control access to it.

For example imagine you want to give students access to a 
library but you don't want them to be able to access the library directly.

First you need to make a library class:
*/
class Library {
  public getBooks() {
    console.log('Getting books...');
  }
}

// Then you make a proxy class that will give students access to the library:
class LibraryProxy {
  constructor(private library: Library) {}

  public getBooks() {
    this.library.getBooks();
  }
}

// Then you make your library:
const library = new LibraryProxy(new Library());
library.getBooks();
Comment

PREVIOUS NEXT
Code Example
Typescript :: laravel orm fetures 
Typescript :: serenity framework break form 
Typescript :: how to ignore a field while desiarilizing in java if its type is not wrong 
Typescript :: after effects how to parent only one property 
Typescript :: subscripts list c# 
Typescript :: How to load plugin scripts in roblox studio command 
Typescript :: language 
Typescript :: cant find the name console 
Typescript :: isolate digits in large number cpp 
Typescript :: .for each typescript 
Typescript :: Moonspell (@moonspellofficial) • Instagram photos and videoswww.instagram.com › moonspellofficial 61.4k Followers, 619 Following, 2421 Posts - See Instagram photos and videos from Moonspell (@moonspellofficial) 
Typescript :: ReturnType FunctionName(FormalParameterList) { Statements ; return ReturnValue; } 
Typescript :: Which one of these is an ideal method to separate sand and salt from water? 
Typescript :: how to set up vuex with typescript 
Typescript :: keynote Invite multiple users to make edits to the same document: 
Typescript :: extracting digits from a number in c++ 
Typescript :: how to make the score add on while its in a loop in python 
Typescript :: can subclass method infere exceptions of its superclass method 
Typescript :: ngbcollapse error with Reactive Forms 
Typescript :: box collision detection 
Typescript :: how to read web page in type script 
Typescript :: code solutions online for public IActionResult Student() { return View(Students Controller 1); } 
Typescript :: stratford school academy 
Typescript :: TypeError: agent_go() takes 0 positional arguments but 1 was given 
Typescript :: c# check type implements generic interface 
Typescript :: typescript new instance of interface 
Typescript :: how to add type using map in typescript 
Typescript :: dotcms elasticsearch query 
Cpp :: c++ time nanoseconds 
Cpp :: c++ generate random char 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =