haps icon indicating copy to clipboard operation
haps copied to clipboard

Possibility to use multiple bases

Open JosXa opened this issue 5 years ago • 0 comments

Suppose the following case:

  • I'm getting a ClientFoo from an external library "Ext". ClientFoo is very complex and it is difficult to do composition over inheritance, and I don't want to extract an interface either as the third-party package might change in the future, causing unnecessary maintenance effort.
  • I want to write my own shared library "Shared" and @inject ClientFoo from "Ext" in some type initializers, so I annotate it with @base and @egg.
  • In the actual application "App" (using both "Ext" and "Shared"), I want to amend ClientFoo with some custom functionality, so I create a subclass ClientBar. It would be valid to inject ClientFoo into types of "Shared", but not necessarily into all the types of "App" because of the extra features required. In "Shared", I would like to rely only on ClientFoo so that its types become reusable but still easy to instantiate, whereas I want to receive concrete ClientBars in "App".

To solve this, my first thought was to annotate ClientBar with both @base and @egg aswell, but that violates the "single base" principle. Is it possible to overcome this issue with the constraints given above? Alternatively, is there a simple way to monkeypatch haps to allow using multiple bases in particular cases?

JosXa avatar Mar 02 '20 21:03 JosXa