refactoringguru / design-patterns-typescript Goto Github PK
View Code? Open in Web Editor NEWDesign Pattern Examples in TypeScript
Home Page: https://refactoring.guru/design-patterns/typescript
License: Other
Design Pattern Examples in TypeScript
Home Page: https://refactoring.guru/design-patterns/typescript
License: Other
I think, all the patterns from this repository should work by "copy and paste", or am i wrong?
For example, in this part of code, typescript will say, that state
property does not exists on Subject.
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?
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.
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 :)
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.
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.
Best,
Vladislav.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.