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

a-tiny-JS-world-OOP #747

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions submissions/igarok88/a-tiny-JS-world-OOP/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { print } from "./js/lib.js";
/* Refer to https://github.com/OleksiyRudenko/a-tiny-JS-world for the task details

Code repository: https://github.com/igarok88/a-tiny-JS-world
Web app: https://igarok88.github.io/a-tiny-JS-world/
*/

class Inhabitants {
constructor(species, name, gender, legs, saying) {
this.species = species;
this.name = name;
this.gender = gender;
this.legs = legs;
this.saying = saying;
}

getInhabitantProps() {
return [this.species, this.name, this.gender, this.legs, this.saying];

Choose a reason for hiding this comment

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

This method has a high chance to fail architecturally over time as it is developer for a very specific use case. However, the current implementation is all right.

To learn what I mean you could read Clean Architecture by Robert Martin at some point in the future.

}
}

class Human extends Inhabitants {
constructor(species, name, gender, legs, hands, saying) {
super(species, name, gender, legs, saying);
this.hands = hands;
}

getInhabitantProps() {
return [
this.species,
this.name,
this.gender,
this.legs,
this.hands,
this.saying,
];
}
}

const dog = new Inhabitants("dog", "Sharik", "male", 4, "woof-woof!");
const cat = new Inhabitants("cat", "Mirzik", "male", 4, "meow-meow!");
const woman = new Human("woman", "Yulia", "famele", 2, 2, "Hi Ihor!");
const man = new Human("man", "Ihor", "male", 2, 2, "Hello Yulia!");

const inhabitants = [dog, cat, woman, man];

inhabitants.forEach((obj) => {
print(obj.getInhabitantProps().join("; "));
});