-
-
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
New index.js (tiny JS) for OOP Exercise #342
Changes from 3 commits
e62a175
943acc8
37c3130
b62f9a7
59760b4
75e81f2
c064a94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
class Entity { | ||
constructor (name, species, gender, saying){ | ||
this.name = name; | ||
this.species = species; | ||
this.gender = gender; | ||
this.saying = saying; | ||
} | ||
} | ||
|
||
class Human extends Entity { | ||
constructor (name, gender, saying){ | ||
super(name, 'Human', gender, saying); | ||
this.legs = 2; | ||
this.hands = 2; | ||
} | ||
} | ||
|
||
class Woman extends Human { | ||
constructor(name, saying){ | ||
super(name, 'Woman', saying) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Men and women are the same species. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, a man and a woman get one species - a person. But it has a gender property to display gender, if that's what you're after. |
||
} | ||
} | ||
|
||
class Animal extends Entity { | ||
constructor(name, gender, saying){ | ||
super(name, 'Animal', gender, saying); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Animal" is not a species. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the name of the main parent class entity to mammal. The animal class has a species - animals, and a person - human species I think this is not a mistake, but simply a manifestation of fantasy in this task. We do not receive a clear structure that should be followed. |
||
this.paws = 4; | ||
} | ||
} | ||
|
||
class Man extends Human { | ||
constructor(name, saying){ | ||
super(name, 'Man', saying) | ||
} | ||
} | ||
|
||
class CatWoman extends Woman { | ||
constructor(name){ | ||
super(name, cat.saying); | ||
} | ||
} | ||
|
||
class Dog extends Animal { | ||
constructor(name, gender, saying){ | ||
super(name, gender, saying) | ||
} | ||
} | ||
|
||
class Cat extends Animal { | ||
constructor(name, gender, saying){ | ||
super(name, gender, saying) | ||
} | ||
} | ||
|
||
const woman = new Woman('Olivia', 'Hello!') | ||
const cat = new Cat('Bonya', 'Girl', 'Meeeeow!') | ||
const dog = new Dog('Dollar', 'Boy', 'Gav-gav!') | ||
const man = new Man('Johny', 'Hellllllooooo!') | ||
const catWoman = new CatWoman('Kitty') | ||
|
||
const allResidents = [woman, man, dog, cat, catWoman] | ||
const allProp = ['name', 'species', 'gender', 'saying', 'legs', 'hands', 'paws'] | ||
|
||
|
||
function toPrint (arrayAllResidents) { | ||
const propToPrint = allProp.filter((propOfObj) => arrayAllResidents[propOfObj] !== undefined) | ||
.map((propOfObj) => arrayAllResidents[propOfObj]).join('; '); | ||
print(propToPrint); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This approach was good enough before OOP. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
done |
||
|
||
function printAllObjects(arrayAllObjects){ | ||
arrayAllObjects.forEach((characters) => { | ||
toPrint(characters); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OleksiyRudenko single character on every iteration |
||
}) | ||
} | ||
|
||
printAllObjects(allResidents); |
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.
entity
is a generic term. Business domain and task requirements are a good source of naming ideas. Name should describe what entity it represents at a given level of abstraction - dog, cat, human, mammal, herbivore - in the given business domain.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.
Done