3 ms·
It's not hard at all and it's actually what the second approach listed by the author shows: class HasRecipient a where get_receiver :: a -> PlayerId
by valcron1000 2y ago
It's not hard at all and it's actually what the second approach listed by the author shows:
class HasRecipient a where
get_receiver :: a -> PlayerId
which adjusted to your example would be
class Timestamped a where
timestamp :: a -> UTCTime
The problem with this approach is that you'll have duplicated data on all instances. In your example, `Quote` has the fields `timestamp` and `sender` in order to satisfy with `Timestamped` and `Msg`. If you had several classes like `Quote` and interfaces like `Timestamped` then you would end up with a lot of duplicated code.
- eddd-ddde 2y agoDoesn't PHP solve this with traits? IIRC you can have traits automatically implement this sort of behavior with a centralized implementation.