4 ms·
The point is that the Golang version is closer to this: interface IPerson { public string Name { get; set; } public int Age { get; set; }
by pdpi 3y ago
The point is that the Golang version is closer to this:
interface IPerson {
public string Name { get; set; }
public int Age { get; set; }
}
public class Person : IPerson
{
public string Name { get; set; }
public int Age { get; set; }
}
public class Employee : IPerson
{
private Person _person;
public string Name {
get { return _person.Name; }
set { _person.Name = value; }
}
public int Age {
get { return _person.Age; }
set { _person.Age = value; }
}
public string Company { get; set; }
}
Employee conforms to the same interfaces as Person, but achieves this via delegation (the famous "favour composition over inheritance" thing)
- myk9001 3y agoWhat advantages does the Golang version have over inheritance? Please, note I don't dispute the "prefer composition over inheritance" thing. In fact, I heartily agree with it. But in this specific case, where every sinle detail of Person is publicly exposed in Employee (no pun intended), I don't see a material difference. If anything, the example uses composition as a tool to implement inheritance on top of. Am I missing something?