|
|
|
|
|
by dlss
4912 days ago
|
|
> When you want to sue one, who will you sue? Okay, since I'm sensing this is about to become a type theory conversation, let's start with the function definition: sue :: Person -> Claim -> Person -> Maybe Money Now you're basically saying that, given the above definition, we have no choice but to have Company implement the Person typeclass. Unfortunately, there is a lot of code already using the Person typeclass for purposes that are absurd when a Corporation is passed. Consider: valid_for_carpool :: [Person] -> Boolean So what to do? One option is to send out emails telling our colleagues to be very careful when using the Person typeclass. The other option is to create a new Suable typeclass, and implement it for both corporations and people. Which one do you prefer? |
|
The obvious solution is to factor out a base class, LegalPerson, with some but not all of the behaviors of the existing Person class. Then derive a separate Company class from LegalPerson. All the stuff we don't want corporations to have, we leave in the existing Person class, so Company doesn't have it.
create a new Suable typeclass
I would view "Suable" as an interface implemented by LegalPerson, and inherited by Person and Company. LegalPerson obviously has to implement lots of interfaces. :-)