Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a sample code for solution? #37

Closed
leemhoon00 opened this issue Oct 17, 2023 · 1 comment
Closed

Is there a sample code for solution? #37

leemhoon00 opened this issue Oct 17, 2023 · 1 comment

Comments

@leemhoon00
Copy link
Contributor

leemhoon00 commented Oct 17, 2023

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?

@neochief
Copy link
Contributor

Hi!

Thanks for the idea! Yes, sure, I can include these examples. Please submit a pull request, and put all of the examples in to a Book directory under each pattern (so that it would be a sibling directory to Conceptual and RealWorld).

This was referenced Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants