-
-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
oop exercise #126
oop exercise #126
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OlStani nice start.
The task requires to print the species the inhabitants belong to.
Also check comments below and a DoD list by bot.
this.hands = hands | ||
} | ||
prepareToPrint() { | ||
return [this.name, this.gender, this.legs, this.hands, this.saying].join(';') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is way to re-use parent class method. It makes sense as this helps to follow SOLID principles. Check the supplementary materials on the task's README.
const dog = new Inhabitants('Bob', 'male', 4, 'woof!') | ||
const cat = new Inhabitants('Kitty', 'female', 4, 'meow!') | ||
const woman = new People('Sara', 'female', 2, 2, 'Hello!') | ||
const catWoman = new People('Bella', 'female', 2, 2, `${cat.saying}`) | ||
const man = new PeopleWithFriends('Mario', 'male', 2, 2, 'Hi!', ['Bob', 'Tom', 'Eva']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By convention class name should be in singular form unless it holds multiple entitites indeed. new People
that returns single human reads a bit weird as there is no option to create multiple humans in a single call of new People
.
No need to have People
and PeopleWithFriends
. This can be resolved by having default friends = []
in a class constructor signature and relevant logic in prepareToPrint
method. Even if friends
has no default value and assigned with none, it's value gonna be undefined
, which is also quite handleable.
Imagine we want to specify neighbours, pets etc (and any such list may be empty or undefined). This should be handled by a single class.
Thank you for contributing to this repo! ❤️️ A Tiny JS World -- OOP exercise check listRelates to Let's do some self-checks to fix most common issues and to make some improvements to the code while reviewers find some time to dedicate it to your submission. Go through the checklist below, fix code as appropriate and mark fulfilled requirements when you genuinely believe you are done. Please, feel free to ask questions here or seek for help in the Students' chat. Check-list - definition of doneMinimal requirements to meet:
Optional level up (not required to implement):
Bonus:
Helpful resources: Sincerely yours, |
@OleksiyRudenko подивись, будь-ласка, коли буде час) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OlStani very well done!
Although species are missing.
@OleksiyRudenko |
Please also check yourself against the checklist above and confirm explicilty you did and followed all listed requirements. |
@OleksiyRudenko |
Does it work as intended end-to-end? |
Види виправив. |
@OleksiyRudenko |
JS не має відношення до уважності і самоперевірки. Дай будь-ласка відповіді на наступні запитання: |
@OleksiyRudenko |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OlStani well improved.
A few improvement touches and we are done.
this.hands = hands | ||
this.friends = friends || [] | ||
} | ||
prepareToPrint() { | ||
return super.prepareToPrint() + '; ' + this.friends.join(', ') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hands output is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
як ти це помічаеш?))
constructor(specie, name, gender, legs, hands, saying, friends) { | ||
super(specie, name, gender, legs, saying) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We assume all instances of Person
are of human species.
We may let users skip passing this property and send a scalar string/constant to the base class' constructor.
@OleksiyRudenko |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sejoker really close.
Go through construction chain to find a way to handle species.
Constructors are regular functions in terms of they handle parameters.
constructor(name, gender, legs, saying, hands, friends) { | ||
super(name, gender, legs, saying) | ||
this.hands = hands | ||
this.friends = friends || [] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may ... send a scalar string/constant to the base class' constructor.
What experession "sends" parameters to a super's constructor?
What is super
and how did you come up with using it?
this.friends = friends || [] | ||
} | ||
prepareToPrint() { | ||
return 'human; ' + super.prepareToPrint() + [this.hands, this.friends.join(', ')].join('; ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We won't need to hardcode species here. We have a base class to handle it. We just need to let it know what species we deal with.
@OleksiyRudenko |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OlStani nice try. Wrong direction though.
Make a step back. And think of what super(...)
actually calls. How constructor is different from a function? Hint: not really. Do we have use variables received by function to send them to the next function we call or we can send anything we want/need?
class Animal extends Inhabitant { | ||
constructor(specie, name, gender, legs, saying, tail) { | ||
super(name, gender, legs, saying) | ||
this.specie = specie |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we have duplication of properties in class hierarchy that violates OOP/SOLID principles.
Shared properties must be owned by a base class and handled in one class.
@OleksiyRudenko |
Не обов'язково тільки параметри наслідуваного класу. Йому можна згодувати що завгодно. Логічно, що якась кількість аргументів йому просто передається. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OlStani well done!
OOP Exercise
Demo |
Code base
The code is submitted in a dedicated feature branch.
Only code files are submitted.
Please, review.