-
-
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 classes #436
Oop classes #436
Conversation
er formatting and changes font-size to rem
Sorry, need help, I can`t understand why I have such problem with this pull request and commits(( |
Hey! Congratulations on your PR! 😎😎😎 Let's do some self-checks to fix most common issues and to make some improvements to the code before reviewers put their hands on the code. Go through the requirements/most common mistakes listed/linked below and fix the code as appropriate. If you have any questions to requirements/common mistakes feel free asking them here or in Students' chat. When you genuinely believe you are done put a comment stating that you have completed self-checks and fixed code accordingly. Also, be aware, that if you would silently ignore this recommendation, a mentor can think that you are still working on fixes. And your PR will not be reviewed. 😒 This PR contains irrelevant commits. You can see this under Commits and/or Files changed tab (you will find a couple of helpful tabs right under the PR title). Most likely, you created a branch for this submission not from the Please fix and add a comment stating that you did this. Universal recommendations:
Also take a note of the requirements above and follow them in all your future projects. By the way, you may proceed to the next task before this one is reviewed and merged. Sincerely yours, |
Check the bot's suggestions and items 2 and 3 here. We'd need to look into your fork's git history to find the exact point where things went wrong. Most likely you had the wrong order of merging ( |
2427b13
to
0084623
Compare
Thanks for great instruction! My problem was in committing to main branch directly, but it seems I did all this steps in the instruction to the wrong commit( |
You just look for a commit that is present on both upstream and fork histories. To see the upstream's history you'd need to clone it separately. P.S. This PR looks good now. Thanks for fixing it. |
Hey! Congratulations on your PR! 😎😎😎 Let's do some self-checks to fix most common issues and to make some improvements to the code before reviewers put their hands on the code. Go through the requirements/most common mistakes linked below and fix the code as appropriate. If you have any questions to requirements/common mistakes feel free asking them here or in Students' chat. When you genuinely believe you are done put a comment stating that you have completed self-checks and fixed code accordingly. Also, be aware, that if you would silently ignore this recommendation, a mentor can think that you are still working on fixes. And your PR will not be reviewed. 😒 Please, make sure that your code follows the requirements based on the most common mistakes as well as both basic and advanced requirements from the original task. Universal recommendations:
By the way, you may proceed to the next task before this one is reviewed and merged. Sincerely yours, |
I checked my code according to the recomendations, please review |
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.
@MarharytaBoichenko good job!
I wonder why having suboptimal implementations that break OOP/SOLID principles?
toPrint() { | ||
return this.properties | ||
.map((prop) => { | ||
const neededProp = this[prop] === undefined ? `no ${prop}` : this[prop]; |
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.
Use Array#filter
to keep props that make sense, then stringify what remains with Array#map
.
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.
ok
this.legs = legs; | ||
this.gender = gender; |
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.
What makes legs
and gender
different from name
in terms of handling and generalization of shared properties?
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.
I changed gender, but not legs, I think it differs because here class Animal extends Inhabitant in parents class Inhabitant there no legs.
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.
Why legs
do not deserve the same handling as name
or gender
?
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.
I think my mistake is that I write legs for Animal but thought about legs as differnt properties , not as legs which Person has ). As I understand if it legs and this property is in Animal and in Person too so we need handle it as name and gender and legs will go from parent class. And if I decide that legs in class Animals is diffferent property - paws so in Animal it will be this.paw = paw . Is it right?
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.
Exactly
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.
thanks, done
super(name, species, friends, saying); | ||
this.legs = legs; | ||
this.gender = gender; | ||
this.properties = [...this.properties, "gender", "legs"]; |
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.
A child class shouldn't directly change inherited property.
A base class shouldn't handle child's properties.
Altogether, every class should handle end-to-end the properties it owns immediately.
Use method overloading and explicit call to inherited method version.
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.
Still an issue.
Use method overloading/overriding and super
API to call inherited method version. super
has other useful applications, not only to call parent's class constructor.
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.
@MarharytaBoichenko great job!
toPrint() { | ||
return super.toPrint(); | ||
} |
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.
No need to overload a method to only explicitly call an inherited version of the method.
class Catwoman extends Cat { | ||
constructor(name, paws, gender, hands, friends) { | ||
super(name, "catwoman", paws, gender, friends); | ||
this.hands = hands; | ||
} | ||
|
||
toPrint() { | ||
return super.toPrint() + `, my hands: ${this.hands}`; | ||
} | ||
} |
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.
Notice, how hybrids break OOP principles: it forces you to duplicate properties.
Although, there are other approaches to achieve this without code duplication, the major learning here should be that when you need to compose properties and behaviours in a non-strictly-hiearchical manner, OOP won't work, and composition pattern is a way to go. Keep in mind and when you face a need to build hybrids, read about and use composition.
OOP Exercise
Demo |
Code base
The code is submitted in a dedicated feature branch.
Only code files are submitted.
Please, review.