First of all mixins are not the best solution, since my interfaces are large and I want to avoid writing empty implementations.
What I am looking for is which approach (technique) is the best for multiple inheritance. My problems is diamond inheritance (yes I read about diamond problem).
// -----------------------
// | Edit |
// -----------------------
// / \
// / \
// / \
// ----------------------- -----------------------
// | DataSetEdit | | OEdit |
// ----------------------- -----------------------
// \ /
// \ /
// \ /
// -----------------------
// | ODataSetEdit |
// -----------------------
The logic is simple.
- Edit is basicaly some
<input type="textbox">with some additional method for validation, masks, input checking ... - OEdit extends edit with some additional methods for styling. Can get properties from server application (WebSocket), send events to server
- DataSetEdit adds methods and properties for handling edit properties (text, color, caption, placeholder ...) - automatically handle changes when current record has changed. (DataSet is class and its data is Object[].)
- ODataSetEdit extends OEdit functionality but need also DataSetEdit methods for handling changes on DataSet.
In one project I use DataSetEdit and in another I always use ODataSetEdit. So in project where ODataSetEdit is used, I only need to copy DataSetEdit functionality.
I do not want to duplicate code in DataSetEdit and ODataSetEdit. I was thinking if I can solve this with:
- some static methods/properties approach
- decorators (maybe on constructor to extend class functionality)
- some static method on DataSetEdit which would be called from ODataSetEdit to extend OEdit functionality with DataSetEdit
- proxy methods and properties from ODataSetEdit to DataSetEdit
- some sort of composition (how would design looks in this concrete example)
ODataSetEdit should extend OEdit but be able to use functionality added in DataSetEdit.
I think that the class structure is logic, how can I avoid need for multiple inheritance in my design? I am sure this is a common problem not related to TypeScript.