Diamond problem is handled in some OOPS languages (eg. curl) by having the repeatedly inherited class as "shared"? I want to know how this works. Also, I want to know the role played by primary and secondary constructors in solving the diamond problem in these OOPS languages when shared strategy is used. Suppose there are 4 classes say A,B,C and D. Let the inheritance structure is B and C inherit A and D inherits both B and C. Each class has a variable say A has a, B has b, C has c and D has d. How does the object creation happens for each class?
How diamond problem in oops is solved using "shared" strategy?
288 Views Asked by Kamalapriya Subramanian At
1
There are 1 best solutions below
Related Questions in OOP
- Access objects variable & method by name
- Why does compiler recognize while(true) at compile time but not if(true)
- Pass variables to extended class
- Cast a superclass type to a subclass type?
- Understanding difference in Swift properties for structs and classes in assignment
- Does exist any way to force child class to have at least one field with a specified attribute?
- Symfony : is it better to use a trait or an intermediary class to complete Controller one?
- (Java) What kind of argument is this? With a
- C++ Implementing a Queue of cars in OOP
- Inheritance in openERP (odoo)
- missing 1 required positional argument: 'key'
- how can Object class in ruby be an instance of it's subclass, class "Class"
- How to force others to obey a specific layout for a child class?
- Class variables in OOP
- define_method in a class method
Related Questions in DIAMOND-PROBLEM
- java how can I overcome multiple inheritance and diamond problam
- Diamond inheritance and the Common Lisp Object System
- What is multiple re-inheritance?
- Creating a Default for ambiguous overloaded function call
- Resolving Diamond Inheritance within Python Classes
- C++ Diamond-like inheritance
- C++: Diamond concerns
- Diamond inheritance with mixed inheritance modifers (protected / private / public)
- Multiple instances of a virtual base class subobject (really) -- no way?
- Virtual Extension Methods in upcoming Java 8 release
- Python multiple inheritance name clashes
- C++ standard: why are some "orders" defined and some not?
- Problems in Interface
- Mixing Templates, Multiple Inheritance, and non-Default Constructor
- errors in my code that involve diamond pattern,
Related Questions in PRIMARY-CONSTRUCTOR
- Moving away from primary constructors
- Null checking with primary constructor in C# 12
- Why do C# 12 primary constructors execute in opposite order?
- CS9110: Cannot use primary constructor parameter that has ref-like type inside an instance member. But why not?
- Should I create private properties for primary constructor parameters in C# 12?
- How diamond problem in oops is solved using "shared" strategy?
- Init a property with a setter in a primary constructor in Kotlin
- Kotlin. How to declare constant?
- Why does Kotlin have two types of constructors?
- How do I pass data from a variable into a constructor using the body of the variable?
- Primary Constructor is not being compiled in C# 6.0
- Kotlin primary and secondary constructors during inheritance
- Kotlin: How to use custom setters in primary constructor
- How to access primary constructor parameters inside secondary constructor kotlin
- C# Primary constructor with body?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Citing Wikipedia at https://en.wikipedia.org/wiki/Multiple_inheritance at the Curl bullet:
From here, without knowing Curl and only with the quote above and this, where it is stated that
Given
I imagine (I don't know for sure) that the coder is responsible to disambiguate the problem by specifying the qualified name of the constructor to run, when invoking a parent constructor from the D(B,C) subclass.
It looks like A has to be declared
shared, and when D is created, B runs a constructor that calls A (primary) constructor, C runs a constructor that calls A (secondary) constructor. The distinction between primary/secondary constructor call is automatic and transparent to the coder.As two A constructors are invoked, two A objects are created in memory, that is the A class is shared with two different subclasses, but there is not a single "shared" A object, but two independent ones (see also virtual/nonvirtual inheritance that is somehow related (C++).)
For what I've read for several different languages, it is almost always the coder that disambiguates the diamond problem with qualification. Languages just define different or similar schemes of giving an error, or having a criteria to choose one of the multiple ambiguous definitions, like specific search order in the inheritance chain. Some other languages don't even allow multiple inheritance, but in some of these you are allowed to extend functionality by some ohter means (like interfaces).