I have an application with the following types setup and in use.
type CompanyFounder {
name: string;
age: number;
salary: number;
sharesHeld: number;
getReasonStartedCompany: string;
};
type NonExecDirector = {
name: string;
age: number;
sharesHeld: number;
string[]: getExternalStuff;
};
I was tasked with adding a new type:
type Person = {
name: string;
age: number;
};
I figured I could improve the code and reduce duplicating fields on related types using the interface segregation principle. Here is what I came up with:
type Person = {
name: string;
age: number;
};
interface Employee extends Person {
salary: number;
}
interface Director extends Person {
sharesHeld: number;
}
interface CompanyFounder extends Director, Employee {
getReasonStartedCompany: string;
}
interface NonExecDirector extends Director {
string[]: getExternalStuff;
}
However, I think I have a problem. The whole system works as it did before the change but I just want to check if there is actually a way around the fact that the Company founder is receiving name and age twice because it extends both Director and Employee.
Just to get people from the server-side/backend devs involved, here is the same problem in a C# example
public interface Person {
string GetName();
int GetAge();
}
public interface Employee : Person {
int GetSalary();
}
public interface Director : Person {
int GetSharesHeld();
}
public interface CompanyFounder : Director, Employee {
string GetReasonStartedCompany();
}
public interface NonExecDirector : Director {
string[] GetExternalStuff();
}
So, problem is that the Company founder is receiving GetName() and GetAge() twice because it implements both Director and Employee.
Can anyone help with this problem?
Why is the director not receiving a salary? Director is an employee which in turn naturally is a person.