How diamond problem in oops is solved using “shared” strategy?










2















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?










share|improve this question
























  • why is this tagged with curl ?

    – hanshenrik
    Nov 14 '18 at 0:28






  • 1





    this is the format in the oops language curl

    – Kamalapriya Subramanian
    Nov 14 '18 at 2:26











  • my concern is not about curl. I want to know how "shared" strategy solves diamond problem?

    – Kamalapriya Subramanian
    Nov 14 '18 at 2:33






  • 1





    @user1067003 - this is the format in the oops language curl. my concern is not about curl. I want to know how "shared" strategy solves diamond problem?

    – Kamalapriya Subramanian
    Nov 14 '18 at 2:39











  • @hanshenrik this probably was tagged with curl because either the OP referred the Wikpedia here or the Wikipedia authors are referring to the same source (or a reference to it) as the OP is.

    – progmatico
    Nov 16 '18 at 16:54















2















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?










share|improve this question
























  • why is this tagged with curl ?

    – hanshenrik
    Nov 14 '18 at 0:28






  • 1





    this is the format in the oops language curl

    – Kamalapriya Subramanian
    Nov 14 '18 at 2:26











  • my concern is not about curl. I want to know how "shared" strategy solves diamond problem?

    – Kamalapriya Subramanian
    Nov 14 '18 at 2:33






  • 1





    @user1067003 - this is the format in the oops language curl. my concern is not about curl. I want to know how "shared" strategy solves diamond problem?

    – Kamalapriya Subramanian
    Nov 14 '18 at 2:39











  • @hanshenrik this probably was tagged with curl because either the OP referred the Wikpedia here or the Wikipedia authors are referring to the same source (or a reference to it) as the OP is.

    – progmatico
    Nov 16 '18 at 16:54













2












2








2








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?










share|improve this question
















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?







oop diamond-problem primary-constructor






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 13:27







Kamalapriya Subramanian

















asked Nov 13 '18 at 20:19









Kamalapriya SubramanianKamalapriya Subramanian

164




164












  • why is this tagged with curl ?

    – hanshenrik
    Nov 14 '18 at 0:28






  • 1





    this is the format in the oops language curl

    – Kamalapriya Subramanian
    Nov 14 '18 at 2:26











  • my concern is not about curl. I want to know how "shared" strategy solves diamond problem?

    – Kamalapriya Subramanian
    Nov 14 '18 at 2:33






  • 1





    @user1067003 - this is the format in the oops language curl. my concern is not about curl. I want to know how "shared" strategy solves diamond problem?

    – Kamalapriya Subramanian
    Nov 14 '18 at 2:39











  • @hanshenrik this probably was tagged with curl because either the OP referred the Wikpedia here or the Wikipedia authors are referring to the same source (or a reference to it) as the OP is.

    – progmatico
    Nov 16 '18 at 16:54

















  • why is this tagged with curl ?

    – hanshenrik
    Nov 14 '18 at 0:28






  • 1





    this is the format in the oops language curl

    – Kamalapriya Subramanian
    Nov 14 '18 at 2:26











  • my concern is not about curl. I want to know how "shared" strategy solves diamond problem?

    – Kamalapriya Subramanian
    Nov 14 '18 at 2:33






  • 1





    @user1067003 - this is the format in the oops language curl. my concern is not about curl. I want to know how "shared" strategy solves diamond problem?

    – Kamalapriya Subramanian
    Nov 14 '18 at 2:39











  • @hanshenrik this probably was tagged with curl because either the OP referred the Wikpedia here or the Wikipedia authors are referring to the same source (or a reference to it) as the OP is.

    – progmatico
    Nov 16 '18 at 16:54
















why is this tagged with curl ?

– hanshenrik
Nov 14 '18 at 0:28





why is this tagged with curl ?

– hanshenrik
Nov 14 '18 at 0:28




1




1





this is the format in the oops language curl

– Kamalapriya Subramanian
Nov 14 '18 at 2:26





this is the format in the oops language curl

– Kamalapriya Subramanian
Nov 14 '18 at 2:26













my concern is not about curl. I want to know how "shared" strategy solves diamond problem?

– Kamalapriya Subramanian
Nov 14 '18 at 2:33





my concern is not about curl. I want to know how "shared" strategy solves diamond problem?

– Kamalapriya Subramanian
Nov 14 '18 at 2:33




1




1





@user1067003 - this is the format in the oops language curl. my concern is not about curl. I want to know how "shared" strategy solves diamond problem?

– Kamalapriya Subramanian
Nov 14 '18 at 2:39





@user1067003 - this is the format in the oops language curl. my concern is not about curl. I want to know how "shared" strategy solves diamond problem?

– Kamalapriya Subramanian
Nov 14 '18 at 2:39













@hanshenrik this probably was tagged with curl because either the OP referred the Wikpedia here or the Wikipedia authors are referring to the same source (or a reference to it) as the OP is.

– progmatico
Nov 16 '18 at 16:54





@hanshenrik this probably was tagged with curl because either the OP referred the Wikpedia here or the Wikipedia authors are referring to the same source (or a reference to it) as the OP is.

– progmatico
Nov 16 '18 at 16:54












1 Answer
1






active

oldest

votes


















1














Citing Wikipedia at https://en.wikipedia.org/wiki/Multiple_inheritance at the Curl
bullet:




Curl allows only classes that are explicitly marked as shared to be
inherited repeatedly. Shared classes must define a secondary
constructor for each regular constructor in the class. The regular
constructor is called the first time the state for the shared class is
initialized through a subclass constructor, and the secondary
constructor will be invoked for all other subclasses.




From here, without knowing Curl and only with the quote above and this, where it is stated that




The object semantics of Curl are similar to those of Java and C++.




Given



 A
/
B(A) C(A)
/
D(B,C)


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).






share|improve this answer

























  • So there is no single shared A's object when instantiating through class D and might be this strategy is same as that of non-virtual strategy of C++. Thank you for your explanation. Atleast now i have some idea about this strategy.

    – Kamalapriya Subramanian
    Nov 19 '18 at 22:42











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288888%2fhow-diamond-problem-in-oops-is-solved-using-shared-strategy%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Citing Wikipedia at https://en.wikipedia.org/wiki/Multiple_inheritance at the Curl
bullet:




Curl allows only classes that are explicitly marked as shared to be
inherited repeatedly. Shared classes must define a secondary
constructor for each regular constructor in the class. The regular
constructor is called the first time the state for the shared class is
initialized through a subclass constructor, and the secondary
constructor will be invoked for all other subclasses.




From here, without knowing Curl and only with the quote above and this, where it is stated that




The object semantics of Curl are similar to those of Java and C++.




Given



 A
/
B(A) C(A)
/
D(B,C)


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).






share|improve this answer

























  • So there is no single shared A's object when instantiating through class D and might be this strategy is same as that of non-virtual strategy of C++. Thank you for your explanation. Atleast now i have some idea about this strategy.

    – Kamalapriya Subramanian
    Nov 19 '18 at 22:42
















1














Citing Wikipedia at https://en.wikipedia.org/wiki/Multiple_inheritance at the Curl
bullet:




Curl allows only classes that are explicitly marked as shared to be
inherited repeatedly. Shared classes must define a secondary
constructor for each regular constructor in the class. The regular
constructor is called the first time the state for the shared class is
initialized through a subclass constructor, and the secondary
constructor will be invoked for all other subclasses.




From here, without knowing Curl and only with the quote above and this, where it is stated that




The object semantics of Curl are similar to those of Java and C++.




Given



 A
/
B(A) C(A)
/
D(B,C)


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).






share|improve this answer

























  • So there is no single shared A's object when instantiating through class D and might be this strategy is same as that of non-virtual strategy of C++. Thank you for your explanation. Atleast now i have some idea about this strategy.

    – Kamalapriya Subramanian
    Nov 19 '18 at 22:42














1












1








1







Citing Wikipedia at https://en.wikipedia.org/wiki/Multiple_inheritance at the Curl
bullet:




Curl allows only classes that are explicitly marked as shared to be
inherited repeatedly. Shared classes must define a secondary
constructor for each regular constructor in the class. The regular
constructor is called the first time the state for the shared class is
initialized through a subclass constructor, and the secondary
constructor will be invoked for all other subclasses.




From here, without knowing Curl and only with the quote above and this, where it is stated that




The object semantics of Curl are similar to those of Java and C++.




Given



 A
/
B(A) C(A)
/
D(B,C)


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).






share|improve this answer















Citing Wikipedia at https://en.wikipedia.org/wiki/Multiple_inheritance at the Curl
bullet:




Curl allows only classes that are explicitly marked as shared to be
inherited repeatedly. Shared classes must define a secondary
constructor for each regular constructor in the class. The regular
constructor is called the first time the state for the shared class is
initialized through a subclass constructor, and the secondary
constructor will be invoked for all other subclasses.




From here, without knowing Curl and only with the quote above and this, where it is stated that




The object semantics of Curl are similar to those of Java and C++.




Given



 A
/
B(A) C(A)
/
D(B,C)


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).







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '18 at 10:39

























answered Nov 18 '18 at 23:49









progmaticoprogmatico

1,9441512




1,9441512












  • So there is no single shared A's object when instantiating through class D and might be this strategy is same as that of non-virtual strategy of C++. Thank you for your explanation. Atleast now i have some idea about this strategy.

    – Kamalapriya Subramanian
    Nov 19 '18 at 22:42


















  • So there is no single shared A's object when instantiating through class D and might be this strategy is same as that of non-virtual strategy of C++. Thank you for your explanation. Atleast now i have some idea about this strategy.

    – Kamalapriya Subramanian
    Nov 19 '18 at 22:42

















So there is no single shared A's object when instantiating through class D and might be this strategy is same as that of non-virtual strategy of C++. Thank you for your explanation. Atleast now i have some idea about this strategy.

– Kamalapriya Subramanian
Nov 19 '18 at 22:42






So there is no single shared A's object when instantiating through class D and might be this strategy is same as that of non-virtual strategy of C++. Thank you for your explanation. Atleast now i have some idea about this strategy.

– Kamalapriya Subramanian
Nov 19 '18 at 22:42


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288888%2fhow-diamond-problem-in-oops-is-solved-using-shared-strategy%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3