You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having to implement the equals & hashable contracts for polymorphic types is often annoying a can be a real pain. In many cases it results in lots of duplicated code or code inheritance from abstract classes.
This approach also violates SRP and DRY principles.
This issue aims to provide an alternative way.
Instead of having each class implement the equals and hashable contracts a dedicated adapter could do the job. The interface might look somewhat like this:
Note the generic parameter of the Set is the concrete implementation FooKey because there may be other Key<Foo> implementations which are derived from a different Foo property and they are not necessarily compatible.
Key extends Single<T> to allow retrieval of the actual key when needed.
The text was updated successfully, but these errors were encountered:
Having to implement the equals & hashable contracts for polymorphic types is often annoying a can be a real pain. In many cases it results in lots of duplicated code or code inheritance from abstract classes.
This approach also violates SRP and DRY principles.
This issue aims to provide an alternative way.
Instead of having each class implement the equals and hashable contracts a dedicated adapter could do the job. The interface might look somewhat like this:
Concrete subtypes would serve as the actual keys, like so:
Now whenever you need to put an implementation of
Foo
into aSet
orMap
you use that key instead.Note the generic parameter of the
Set
is the concrete implementationFooKey
because there may be otherKey<Foo>
implementations which are derived from a differentFoo
property and they are not necessarily compatible.Key
extendsSingle<T>
to allow retrieval of the actual key when needed.The text was updated successfully, but these errors were encountered: