Hi all, Am 20.04.2016 um 16:44 schrieb guilhermebla...@gmail.com: > If I want to hire/move a person to a department that is registered in the > system, but is not a 3rd party company person, how would you achieve that > considering the following class structure? > > class Person {} > class Employee extends Person {} > class AssociateEmployee extends Employee {} > class Manager extends Employee {} > > Considering your function: > > function assignToDepartment<T>(T $person) : bool; > > Generic type "T" in the function prototype needs to accept Person (new > hire), Employee and Manager (transfer), but not AssociateEmployee. > Considering upper bounds support only, your best bet is "T extends Person", > but that would accept AssociateEmployee to be provided, which contradicts > the business rule. Accepting anything lower in the hierarchy prevents new > hires. > That's when lower bounds comes into play. If you define as "T super Manager", > all Person, Employee and Manager gets accepted, but not the > AssociatedEmployee, matching properly the business rule.
I have to strongly disagree with the last sentence here: "T super Manager" only fulfills your business rule by accident. If you add a "TeamLeader extends Employee" class, your complete example falls apart and shows that it is a very bad idea to introduce a "T super X" requirement. You really want "T implements Person except AssociateEmployee" so that you can use them like you would use bitmasks. I think that fundamentally contradicts how interfaces and inheritance work. The type in the generic should specify which contract (Base class/interface) you require at least inside the generic class/function. Everything else is really strange to me. What about interfaces? If Manager or Employee implement Serializable, will all other classes that implement Serializable also be allowed here? Please let's not implement "T super X" kind of generics for use cases that really need something different. Thanks, Dennis -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php