👨🏻💻 Démarrer votre carrière de développeur PRO avec Angular :
www.angularsenior.fr/apply
Dans cette vidéo, j’aimerais vous dire pourquoi j’ai détesté les "Design Patterns" pendant des années.
Je voyais ces graphes avec 70 classes...
C’était incompréhensible et ça me dégoutait, car je n’ai jamais compris à quoi cela pourrait réellement me servir dans la vraie vie !
Je vais donc vous partager une discussion privée que j’ai eue avec un développeur Senior lorsque j’étais à Atos et qui m’a permis aujourd'hui de comprendre RÉELLEMENT à quoi pourrait me servir les Design Patterns.
Bon visionnage,
Simon.
🖥 CODE DU DESIGN PATTERN BUILDER (TYPESCRIPT) 🖥
Le code de cette vidéo à "copier-coller" et à adapter à vos projets.
```
// Design Pattern "Builder" with TypeScript //
class SnackbarBuilder {
constructor(message: string) {
this.message = message;
}
setTitle(title: string) {
this.title = title;
return this;
}
setSticky(sticky: string) {
this.sticky = sticky;
return this;
}
private setType(type: string) {
this.type = type;
return this;
}
private setIcon(icon: string) {
this.icon = icon;
return this;
}
private setCanClose(canClose: boolean) {
this.canClose = canClose;
return this;
}
private setDuration(duration: number) {
this.duration = duration;
return this;
}
buildSuccess() {
this.setType('success');
this.setDuration(3000);
this.setCanClose(false);
return this.build();
}
buildInfo() {
this.setType('information');
this.setDuration(3000);
this.setCanClose(false);
return this.build();
}
buildWarning() {
this.setType('warning');
this.setCanClose(true);
return this.build();
}
buildError() {
this.setType('error');
this.setCanClose(true);
return this.build();
}
private build() {
return new Snackbar(
this.message,
this.title,
this.sticky,
this.type,
this.icon,
this.canClose,
this.duration
);
}
}
// Use case //
const snackbar = new SnackbarBuilder(message)
.setSticky(true)
.buildInfo();
```
20 июл 2022