UML: Unified Modeling Language
통합 모델링 언어
시스템을 모델로 표현해주는 대표적인 모델링 언어
구현 소스
function Coffee() {
this.name= "Coffee"
}
Coffee.prototype.getName = function() {
return this.name
};
Coffee.prototype.setName = function(name) {
this.name
};
Coffee.prototype.display = function() {
console.log(this.name)
};
let coffee = new Coffee();
function Espresso() {
Coffee.call(this);
}
// Coffee 생성자 상속
Espresso.prototype = Object.create(Coffee.proto, { constructor: {
value: Espresso,
configurable: true,
enumerable: true,
writable: true
}
});
let espresso = new Espresso();
espresso.setName("Espresso");
구현 소스
function ICoffee() {
}
ICoffee.prototype.getName = function() {
throw new Error(' You have to implement the method doSomething!');
};
ICoffee.prototype.setName = function(name) {
throw new Error(' You have to implement the method doSomething!');
};
ICoffee.prototype.display = function() {
throw new Error(' You have to implement the method doSomething!');
};
function Espresso() {
this.name = "Espresso"
}
// ICoffee 생성자 구현
Espresso.prototype(ICoffee.prototype, {
constructor: {
value: Espresso,
configurable: true,
enumerable: true,
writable: true
}
});
// Espresso 함수 오버라이딩
Espresso.prototype.getName = function() {
return this.name
};
Espresso.prototype.setName = function(name) {
this.name
};
Espresso.prototype.display = function() {
console.log(this.name)
};
var espresso = new Espresso();
console.log(espresso.getName());
// > Espresso
espresso.display();
// > Espresso
구현 소스
function Espresso() {
this.name = "Espresso";
}
Espresso.prototype.display = fucntion() {
console.log(this.name);
};
fucntion Baristar() {
// Coffee 객체 프로퍼티로 정의
this.espressoMachine = null;
}
Barista.prototype.setEspressoMachine = fucntion(espressoMachine) {
this.espressoMachine = espressoMachine;
}
Barista.prototype.makeEspresso = function() {
var espresso = this.espressoMachine.makeEspresso();
return espresso;
}
function EspressoMachine() {
this.price = 3000000
}
EspressoMachine.prototype.makeEspresso = function() {
return new Espresso();
}
var barista = new Barista();
var espressoMachine = new EspressoMachine();
barista.setEspressoMachine(espressoMachine);
var espresso = barista.makeEspresso();
espresso.display();
// > Espresso
구현 소스
fucntion CoffeBeans() {
this.countryOfOrigin = "Colombia";
}
CoffeeBeans.prototype.toString = function() {
return "CoffeeBeans ["+ this.countryOfOrigin+"]";
}
function Espresso() {
this.name = "Espresso";
}
Espresso.prototype.toTring = function() {
return "Espresso";
}
function Milk() {
this.name = "Milk";
}
Milk.prototype.toString() {
return "Milk";
}
function CafeLatte() {
this.name = "CafeLatte';
// Coffee 객체 프로퍼티로 정의
this.espresso = null;
this.milk = null;
}
// Coffe 객체 프로퍼티를 외부에서 설정하는 함수를 제공한다.
CafeLatte.prototype.setEspresso = function(espresso) {
this.espresso = espresso;
}
CafeLatte.prototype.setMilk = function(milk) {
this.milk = milk;
};
CafeLatte.prototype.display = function() {
console.log(this.name + "(" + this.espresso + "+" + this.milk + ")");
};
function Barista() {
this.espressoMachine = null;
}
Barista.prototype.setEspressoMachine = function(espressoMachine) {
this.espressoMachine = espressoMachine;
}
Barista.prototype.makeEspresso = function() {
var coffeBeans = new CoffeeBeans();
var espresso = this.espressoMachine.makeEspresso(coffeBeans);
return espresso;
};
Barista.prototype.makeCafeLatte = function() {
var coffeeBeans = new CoffeBeans();
var espresso = this.espressoMachine.makeEspresso(coffeBeans);
var milk = new Milk();
var cafeLatte = new CafeLatte();
cafeLatte.setEspresso(espresso);
cafeLatte.setMilk(milk);
return cafeLatte;
};
function EspresooMachine() {
this.price = 3000000;
}
EspressoMachine.prototype.makeEspresso = function(coffeBeans) {
fonsole.log(""+coffeBeans);
return new Espresso();
}
var barista = new Barista();
var espressoMachine = new EspressoMachine();
barista.setEspressoMachine(espressoMachine);
var cafeLatte = barista.makeCafeLatte();
cafeLatte.display();
// > CafeLatte(Espresso+Milk)