I am curious about how to effectively implement the example below. I am working on abstracting some fundamental functionality of a House. The scenario I encountered is as follows:
Imagine there is an abstract Animal class that is extended like this:
abstract class Animal{
constructor(age:number){
this.age = age;
}
age:number;
}
class Dog extends Animal{
constructor(age:number){
super(age);
}
bark(){
console.log("Bark");
}
}
class Cat extends Animal{
constructor(age:number){
super(age);
}
meow(){
console.log("Meow");
}
}
The main objective here is to establish this as a foundational class within the application, with various animal house classes extending it and utilizing its core functions.
abstract class House{
animals:Animal[];
addAnimal(humanAge:number){
const animalAge = humanAge/7;
// How can we properly add an animal here? Similar to something like animals.push(new Animal(animalAge));
}
}
class DogHouse extends House{
doSomethingElseHERE(){
console.log("Something else")
}
}
new DogHouse().addAnimal(23); //What would be an effective solution to seamlessly integrate this in all animal houses?
So, what would be a suitable implementation for the "add" function in the abstract class House?