Skip to content

Is there a sample code for solution? #37

Closed
@leemhoon00

Description

@leemhoon00

Hi, I find RefactoringGuru's Problem and Solution scenarios very easy to understand and of high quality.

However, I can't find the sample code for the Problem and Solution sections, so I have to implement the samples like this:

// Decorator Pattern
interface Notifier {
  send(message: string): void;
}

class EmailNotifier implements Notifier {
  constructor(private emails: string[]) {}

  send(message: string): void {
    console.log(`Sending email to ${this.emails}: ${message}`);
  }
}

class SMSDecorator implements Notifier {
  constructor(private notifier: Notifier) {}

  send(message: string): void {
    console.log(`Sending SMS: ${message}`);
    this.notifier.send(message);
  }
}

class FacebookDecorator implements Notifier {
  constructor(private notifier: Notifier) {}

  send(message: string): void {
    console.log(`Sending Facebook message: ${message}`);
    this.notifier.send(message);
  }
}

class SlackDecorator implements Notifier {
  constructor(private notifier: Notifier) {}

  send(message: string): void {
    console.log(`Sending Slack message: ${message}`);
    this.notifier.send(message);
  }
}

const emailNotifier = new EmailNotifier([
  "user1@example.com",
  "user2@example.com",
]);

const combinedNotifier = new SlackDecorator(
  new FacebookDecorator(new SMSDecorator(emailNotifier))
);

combinedNotifier.send("Important message: House is on fire!");

I am implementing all of the Solution Code like this. Can I contribute to this repository?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions