GithubHelp home page GithubHelp logo

refactoringguru / design-patterns-typescript Goto Github PK

View Code? Open in Web Editor NEW
1.0K 1.0K 148.0 185 KB

Design Pattern Examples in TypeScript

Home Page: https://refactoring.guru/design-patterns/typescript

License: Other

TypeScript 100.00%
design-patterns typescript

design-patterns-typescript's People

Contributors

alfonsograziano avatar dependabot[bot] avatar leemhoon00 avatar lex111 avatar moritz-t-w avatar neochief avatar pheetah avatar userbit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

design-patterns-typescript's Issues

Is there a sample code for solution?

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([
  "[email protected]",
  "[email protected]",
]);

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?

Returned wrong attribute on Builder pattern | prototype example

This is not only related to the typescript code samples, it is more related to the book, but I can not find where to submit that kind of issue.

Issue

Once we make attribute: result we should return this.result not this.manual . I know this is only a prototype, but still, I guess this should be applied.

image

Best,
Vladislav.

RealWorld examples

Hello, I would like to work on RealWorld examples for this repository (this is my first contribution to a project). Before to start I would really appreciate an ok from the maintainers and, if needed, advices. I will create the PR with examples in the next days :)

Memento: caretaker shouldn't have access to state but it does

In the memento conceptual example, you have the next interface of Memento that will be used by caretakers:

interface Memento  {
    getState(): string;
    getName(): string;
    getDate(): string;
}

Following the pattern - caretakers shouldn't have access to the state that memento stores. But with the above interface, we can call memnto.getState() in any caretaker and receive the state because caretakers operate with memntos with this interface.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.