mardi 12 janvier 2021

Subclass extending the same superclass using another subclass within itself

The schema is like below

{
   id
   name
   surname
   employees {
      id
      name
      surname
   }
}

I was wondering if its oop representation could be

class Person {
   id
   name
   surname
}

class Employee extends Person {}

class Supervisor extends Person {
   List<Employee> employees;
}

So two classes will be inherited from the same class but one of them uses the other one within it self.

If this is not a good idea, what would be a better way of constructing this schema.

Aucun commentaire:

Enregistrer un commentaire