Time and Location - We’re HYBRID!
The Diamond Problem Solved!
Traditionally in class based OOP languages, both the fields and methods from the super-classes are inherited by the sub-classes. However this may cause some serious problems in multiple inheritance, e.g. most notably the diamond problem. In this paper, we propose to stop inheriting data fields as a clean and general solution to such problems. We first present a design pattern called DDIFI (which stands for Decoupling Data Interface From data Implementation) to cleanly achieve multiple inheritance in C++, which can handle class fields of the diamond problem exactly according to the programmers’ intended application semantics. It gives programmers flexibility when dealing with the diamond problem for instance variables: each instance variable can be configured either as one joined copy or as multiple independent copies in the implementation class. The key ideas are:
- Decouple data interface from data implementation, by stopping inheriting data fields
- In the regular methods implementation use virtual property methods instead of direct raw fields
- After each semantic branching add (and override) the new semantic assigning property
Then we show our method is general enough, and also applicable to any OOP languages:
- That natively support multiple inheritance (e.g. C++, Python, OCaml, Lisp, Eiffel, etc.), or
- Single inheritance languages that support default interface methods (e.g. Java, C# etc.), or
- Single inheritance languages that support mixins, and conditional compilation (e.g. static if in D), or traits (e.g. Scala).
We have demo implementation of this design pattern DDIFI in these 9 languages, since this is C++ talk, we will mostly talk about the C++ implementation.
YuQian Zhou: Ph.D from Oxford Univ.; previous Google engineer; startup founder.
A Word From Our Sponsor
Please thank JFrog and Conan for sponsoring the our Meetup account!
Please thank Microsoft for sponsoring our meeting room and Teams account!