Let's say I have those three classes:
function Basket() {
this.catches = []
}
Basket.prototype.addCatch = function(catch) {
catches.push(catch)
}
function Pole() {
}
Pole.prototype.catchFish = function() {
return "fish"
}
function Fisherman() {
this.pole = new Pole()
this.basket = new Basket()
}
Now when I create a Fisherman
I can catch a fish and put it into the basket.
Now I would like to do both in one call. The way I implemented it now is the following:
function Fisherman() {
this.pole = new Pole()
this.basket = new Basket()
this.utils = {}
this.utils.catchAndStore = function() {
let { pole, basket } = this
basket.addCatch(pole.catchFish())
}.bind(this)
}
I seems to work but does not feel quite right. What would be a good way to structure my class to achieve this goal? Or should this complexity be let out of this class?