Skip to content
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

Merged
merged 10 commits into from
Sep 26, 2022
Merged

Oop classes #436

merged 10 commits into from
Sep 26, 2022

Conversation

MarharytaBoichenko
Copy link
Contributor

OOP Exercise

Demo |
Code base

The code is submitted in a dedicated feature branch.

Only code files are submitted.

Please, review.

@MarharytaBoichenko
Copy link
Contributor Author

Sorry, need help, I can`t understand why I have such problem with this pull request and commits((
Where was the first mistake why I have all this files in my branch

@OleksiyRudenko OleksiyRudenko added the irrelevant-commits Commits not related to current task label Sep 5, 2022
@github-actions
Copy link

github-actions bot commented Sep 5, 2022

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 main branch as instructed in section B122 of submission instructions.

Please fix and add a comment stating that you did this.

How to fix.

Universal recommendations:

  • Give variables and functions meaningful names. Avoid generic names like item, element, key, object, array or their variations. Exception: helper functions that are specifically and intentionally designed to be multipurpose.
  • Function names should start with a verb as they denote actions; variables are normally nouns; boolean variables/functions start with is, does, has etc; variable containing multiple entities and functions returning lists contain entity name in plural form.
  • Have consistent code style and formatting. Employ Prettier to do all dirty work for you.
  • Use common sense or seek for an advice whenever requirements look ambiguous or unclear.

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,
Submissions Kottachecker 😺

@OleksiyRudenko
Copy link
Member

OleksiyRudenko commented Sep 5, 2022

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 (main should be merged in the feature branch, not vice versa) or committed directly to main on your fork.

@MarharytaBoichenko
Copy link
Contributor Author

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(
I took commit 8d092ec, the last in Popup, because in Dom task I committed to main but now I see all popup commits here(
It seems I can-t understand what commit I need for this step - " identify the most recent commit that both usptream and origin share (c4ebbab in our example)"

@OleksiyRudenko OleksiyRudenko removed the irrelevant-commits Commits not related to current task label Sep 13, 2022
@OleksiyRudenko
Copy link
Member

OleksiyRudenko commented Sep 13, 2022

It seems I can-t understand what commit I need for this step - " identify the most recent commit that both usptream and origin share (c4ebbab in our example)"

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.

@github-actions
Copy link

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:

  • Make sure your code follows General Requirements
  • Use common sense or seek for an advice whenever requirements look ambiguous or unclear.

By the way, you may proceed to the next task before this one is reviewed and merged.

Sincerely yours,
Submissions Kottachecker 😺

@MarharytaBoichenko
Copy link
Contributor Author

I checked my code according to the recomendations, please review

@OleksiyRudenko OleksiyRudenko added the self-check-done Student confirmed that self-checks against requirements/common-mistakes are done label Sep 20, 2022
Copy link
Member

@OleksiyRudenko OleksiyRudenko left a 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];
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment on lines 43 to 44
this.legs = legs;
this.gender = gender;
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@OleksiyRudenko OleksiyRudenko Sep 20, 2022

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?

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly

Copy link
Contributor Author

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"];
Copy link
Member

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.

Copy link
Member

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.

@OleksiyRudenko OleksiyRudenko self-assigned this Sep 20, 2022
Copy link
Member

@OleksiyRudenko OleksiyRudenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarharytaBoichenko great job!

Comment on lines +47 to +49
toPrint() {
return super.toPrint();
}
Copy link
Member

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.

Comment on lines +81 to +90
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}`;
}
}
Copy link
Member

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.

@OleksiyRudenko OleksiyRudenko merged commit 3279480 into kottans:main Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
self-check-done Student confirmed that self-checks against requirements/common-mistakes are done task-TJSW-OOP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants