Skip to content

Instantly share code, notes, and snippets.

@moonpyk
Created December 8, 2016 21:05
Show Gist options
  • Select an option

  • Save moonpyk/b1bdfcbc4799dd69d11c45e713d33c80 to your computer and use it in GitHub Desktop.

Select an option

Save moonpyk/b1bdfcbc4799dd69d11c45e713d33c80 to your computer and use it in GitHub Desktop.
abstract class CasClinique {
hasFievre(): boolean {
return true;
}
symptomes(): string[] {
return null;
}
hasSymptome(s: string) {
var ss = this.symptomes();
if (ss == null) {
return false;
}
return ss.indexOf(s) > 0;
}
}
class Bronchite extends CasClinique {
symptomes(): string[] {
return ["toux"]
}
}
class DepressionNerveuse extends CasClinique {
hasFievre():boolean {
return false;
}
symptomes():string[] {
return ["tristesse"]
}
}
class Patient {
private _maladie: CasClinique;
constructor(m: CasClinique) {
this._maladie = m;
}
examineCerveau() {
if (this._maladie.hasSymptome("tristesse")) {
console.log("ça sent la dépression")
}
}
examinePoumons() {
if (this._maladie.hasFievre() && this._maladie.hasSymptome("toux") ) {
console.log("Patient tousse")
}
}
examineTroudbal() {
if (this._maladie.hasSymptome("malaucul") ) {
console.log("Malocul")
}
}
}
var bebert = new Patient(new Bronchite())
bebert.examinePoumons();
bebert.examineTroudbal();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment