Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Driver {
- private command: Command;
- constructor(command: Command) {
- this.command = command;
- }
- execute() {
- this.command.execute();
- }
- };
- class Engine {
- private state: boolean;
- constructor() {
- this.state = false;
- }
- on() {
- this.state = true;
- }
- off() {
- this.state = false;
- }
- };
- interface Command {
- execute: () => void;
- }
- class OnStartCommand implements Command {
- private engine: Engine;
- constructor(engine: Engine) {
- this.engine = engine;
- }
- execute() {
- this.engine.on();
- }
- };
- class onSwitchOffCommand implements Command {
- private engine: Engine;
- constructor(engine: Engine) {
- this.engine = engine;
- }
- execute() {
- this.engine.off();
- }
- };
- const engine = new Engine();
- console.log(engine)
- const onStartCommand = new OnStartCommand(engine);
- const driver = new Driver(onStartCommand)
- driver.execute()
- console.log(engine)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement