August 16, 2023: The Diamond Problem Solved!

Time and Location - We’re HYBRID!

August 16, 2023 at 7:00 PM

In Person:
Microsoft Redmond Reactor | 3709 157th Ave NE, Redmond, WA 98052
Conf Room 20/1034 (14) Alder Reactor

On Line Using Microsoft Teams
Meeting ID: 221 084 547 694
Passcode: zRSbFd

Call in (audio only)
+1 323-849-4874,,731463717#<tel:+13238494874,,731463717#> United States, Los Angeles
Phone Conference ID: 731 463 717#


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:

  1. Decouple data interface from data implementation, by stopping inheriting data fields
  2. In the regular methods implementation use virtual property methods instead of direct raw fields
  3. 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:

  1. That natively support multiple inheritance (e.g. C++, Python, OCaml, Lisp, Eiffel, etc.), or
  2. Single inheritance languages that support default interface methods (e.g. Java, C# etc.), or
  3. 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.

Speaker Bio

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!