TIL IM-6

baymaxx·2021년 3월 3일
0
post-thumbnail

Class Structure

BARE MINIMUM REQUIREMENTS


  • npm
    node를 실행하기 위한 모듈을 설치하기 : npm install

  • src 디렉토리(폴더) 안에 es6, pseudoclassical디렉토리존재한다. 각각 해당하는 패턴으로 구현해라.
    pseudoclassical: prototype, constructor 키워드 이용
    ES6: super, extends, class 키워드 이용

  • Sub Classing
    첫번째 class인 Grub.js부터 작성해라. Grub는 다른 타입인 bees의 부모클래스가 될것이다. 구현이 끝나 면 npm test를 통해 테스트를 진행해라.
    아래 지정된 순서대로 저장소를 통해 작업해라.

  • Grub
    -an age property that is set to 0
    -a color property that is set to pink
    -a food property that is set to jelly an eat method
    -an eat method that returns 'Mmmmmmmmm jelly'

  • Bee
    -call the Grub superclass
    -an age property that is set to 5
    -a color property that is set to yellow
    -a job property that is set to keep on growing
    -a food property that is inherited from grub
    -an eat method that is inherited from grub

  • HoneyMakerBee
    -call the Bee superclass
    -an age property that is set to 10
    -a job property that is set to make honey
    -a honeyPot property that is set to 0
    -a makeHoney method that adds 1 to that honeyBee's honeyPot
    -a giveHoney method that subtracts 1 from that honeyBee's honeyPot
    -a food property that is inherited from grub
    -an eat method that is inherited from grub
    -a color property inherited from bee that is set to yellow

  • ForagerBee
    -call the Bee superclass
    -an age property that is set to 10
    -a job property that is set to find pollen
    -a canFly property that is set true
    -a treasureChest property that is set to an empty array []
    -a forage method that allows the bee to add a treasure to the treasureChest
    -a food property that is inherited from grub
    -an eat method that is inherited from grub
    -a color property inherited from bee that is set to yellow

  • RetiredForagerBee
    -call the ForagerBee superclass
    -an age property that is set to 40
    -a job property that is set to gamble
    -a canFly property that is set to false
    -a color property that is set to grey
    -a forage method that returns "I am too old, let me play cards instead"
    -an always winning gamble method that allows the bee to add a treasure to the treasureChest
    -a food property that is inherited from grub
    -an eat method that is inherited from grub
    -a treasureChest property inherited from ForagerBee that is set to an empty array []

//Grub.js
var Grub = function() {
this.age = 0
this.color = "pink"
this.food = "jelly"
};
Grub.prototype.eat = function(){
return "Mmmmmmmmm jelly"
}

//Bee.js
var Bee = function(age, color, food) {
Grub.call(this) //constructor안썼나? es6인가?
this.age = 5
this.color = "yellow"
this.job = "Keep on growing"
}
Bee.prototype = Object.create(Grub.prototype);
Bee.prototype.constructor = Bee; //이게 맞나 뭔가 빠진것같은데

//HoneyMakerBee
var HoneyMakerBee = function(age, color, honeyPot, job) {
Bee.call(this)
this.age = 10
this.job = "make honey"
this.honeyPot = 0
this.color = "yellow"->색그대로 가져오는데 또 이렇게 해줘야하나? 안해도됨
}
HoneyMakerBee.prototype = Object.create(Bee.prototype);
HoneyMakerBee.prototype.constructor = HoneyMakerBee;

HoneyMakerBee.prototype.makeHoney = function() {
this.honeyPot++
}
HoneyMakerBee.prototype.giveHoney = function() {//여기는 아무것도 안넣는다? 인자가 필요하다고 하면 그럼 여기도 통일성있게 this해야하는거아냐?
this.honeyPot--
}

//ForagerBee
var ForagerBee = function(age, job, color, canFly, treasureChest) { //안넣고 돌려보기 안넣어도 됨
Bee.call(this)
this.age = 10
this.job = "find pollen"
this.color = "yellow"
this.canFly = true
this.treasureChest = []
}
ForagerBee.prototype = Object.create(Bee.prototype);
ForagerBee.prototype.constructor = ForagerBee;

ForagerBee.prototype.forage = function(treasure) { //여기는 treasure 넣고 
this.treasureChest.push(treasure)
}

//RetiredForagerBee
var RetiredForagerBee = function(age, job, cnaFly, color) {
ForagerBee.call(this)
this.age = 40
this.job = "gamble"
this.canFly = false
this.color = "grey"
//this.treasure = []//이게 왜있어야됨?this.treasureChest = []이게 맞는거아닌가
}
RetiredForagerBee.prototype = Object.create(ForagerBee.prototype);
RetiredForagerBee.prototype.constructor = RetiredForagerBee;

RetiredForagerBee.prototype.forage = function() {
return "I am too old, let me play cards instead"
}
RetiredForagerBee.prototype.gamble = function(treasure) {
this.treasureChest.push(treasure)
}
//Grub.js
class Grub {
constructor(age = 0, color = 'pink', food = 'jelly') {
this.age = age
this.color = color
this.food = food
}
eat() {
return "Mmmmmmmmm jelly"
}
}

//Bee.js
class Bee extends Grub{
constructor(age, color){
super(age, color)
this.age = 5
this.color = 'yellow'
this.job = 'Keep on growing'
}
}

//HoneyMakerBee
class HoneyMakerBee extends Bee{
constructor(age, job){
super(age,job)
this.age = 10
this.job ='make honey'
this.honeyPot = 0
}
makeHoney(){
this.honeyPot++
}
giveHoney(){
this.honeyPot--
}
}

//ForagerBee
class ForagerBee extends Bee{
consturctor(age, job){
super(age, job)
this.age = 10
this.job = 'find pollen'
this.canFly = true
this.treasureChest = []
}
forage (treasure) {
this.treasureChest.push(treasure)
}
}

//RetiredForageBee
class RetiredForageBee {
constructor() {
super()
this.age = 40
this.job = 'gamble'
this.canFly = false
this.color = "grey"
}
forage() {
return "I am too old, let me play cards instead"
}
gamble(treasure) {
this.treasureChest.push(treasure)
}
}

0개의 댓글