Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CPU {
- start(): void {
- console.log("CPU started");
- }
- }
- class Memory {
- load(position: number, data: string): void {
- console.log(`Loading data ${data} at position ${position}`);
- }
- }
- class HardDrive {
- read(position: number, size: number): string {
- console.log(`Reading ${size} data from position ${position}`);
- return "data";
- }
- }
- // Facade: This is the class that simplifies the interface to the subsystems.
- class Computer {
- private cpu: CPU;
- private memory: Memory;
- private hardDrive: HardDrive;
- constructor() {
- this.cpu = new CPU();
- this.memory = new Memory();
- this.hardDrive = new HardDrive();
- }
- start(): void {
- this.cpu.start();
- const data = this.hardDrive.read(1000, 200);
- this.memory.load(0, data);
- console.log("Computer started");
- }
- }
- // Client Code: The client interacts with the subsystems through the simplified interface provided by the facade.
- const computer = new Computer();
- computer.start();
- // Output:
- // CPU started
- // Reading 200 data from position 1000
- // Loading data data at position 0
- // Computer started
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement