Skip to content

Instantly share code, notes, and snippets.

@bgergo
Created July 28, 2016 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgergo/5e383805cb4fd58c0e0fb09bbcd21320 to your computer and use it in GitHub Desktop.
Save bgergo/5e383805cb4fd58c0e0fb09bbcd21320 to your computer and use it in GitHub Desktop.
export default class AbstractAnimal {
constructor(ModelClass) {
if (!ModelClass) {
throw new Error('Model is required to get the config obj');
}
this.config = {
type: '',
noise: ''
};
Object.assign(this.config, ModelClass.prototype.config);
this.ModelClass = ModelClass;
}
say() {
if (!this.config.noise)
throw new Error("No one knows this sound");
return this.config.noise;
}
sleepySay() {
return new Promise((resolve, reject) => {
if (!this.config.noise)
throw new Error("No one knows this sound");
resolve(this.config.noise);
});
}
}
import AbstractAnimal from './AbstractAnimal';
export class DogModel {
constructor () {
this.config = {
type: 'dog',
noise: 'woof'
}
}
}
export default class Dog extends AbstractAnimal {
constructor() {
super(DogModel);
Object.assign(this, DogModel.prototype.config)
}
say() {
return super.say();
}
sleepySay() {
return super.sleepySay();
}
}
import AbstractAnimal from './AbstractAnimal';
export class FoxModel {
constructor () {
this.config = {
type: 'fox',
noise: null
}
}
}
export default class Fox extends AbstractAnimal {
constructor() {
super(FoxModel);
Object.assign(this, FoxModel.prototype.config)
}
say() {
super.say();
}
sleepySay() {
return super.sleepySay();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment