How diamond problem in oops is solved using “shared” strategy?
up vote
2
down vote
favorite
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
|
show 6 more comments
up vote
2
down vote
favorite
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
why is this tagged withcurl
?
– hanshenrik
Nov 14 at 0:28
1
this is the format in the oops language curl
– Kamalapriya Subramanian
Nov 14 at 2:26
my concern is not about curl. I want to know how "shared" strategy solves diamond problem?
– Kamalapriya Subramanian
Nov 14 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 at 2:39
@hanshenrik this probably was tagged withcurl
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 at 16:54
|
show 6 more comments
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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
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
oop diamond-problem primary-constructor
edited Nov 15 at 13:27
asked Nov 13 at 20:19
Kamalapriya Subramanian
164
164
why is this tagged withcurl
?
– hanshenrik
Nov 14 at 0:28
1
this is the format in the oops language curl
– Kamalapriya Subramanian
Nov 14 at 2:26
my concern is not about curl. I want to know how "shared" strategy solves diamond problem?
– Kamalapriya Subramanian
Nov 14 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 at 2:39
@hanshenrik this probably was tagged withcurl
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 at 16:54
|
show 6 more comments
why is this tagged withcurl
?
– hanshenrik
Nov 14 at 0:28
1
this is the format in the oops language curl
– Kamalapriya Subramanian
Nov 14 at 2:26
my concern is not about curl. I want to know how "shared" strategy solves diamond problem?
– Kamalapriya Subramanian
Nov 14 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 at 2:39
@hanshenrik this probably was tagged withcurl
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 at 16:54
why is this tagged with
curl
?– hanshenrik
Nov 14 at 0:28
why is this tagged with
curl
?– hanshenrik
Nov 14 at 0:28
1
1
this is the format in the oops language curl
– Kamalapriya Subramanian
Nov 14 at 2:26
this is the format in the oops language curl
– Kamalapriya Subramanian
Nov 14 at 2:26
my concern is not about curl. I want to know how "shared" strategy solves diamond problem?
– Kamalapriya Subramanian
Nov 14 at 2:33
my concern is not about curl. I want to know how "shared" strategy solves diamond problem?
– Kamalapriya Subramanian
Nov 14 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 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 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 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 at 16:54
|
show 6 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
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).
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 at 22:42
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
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).
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 at 22:42
add a comment |
up vote
1
down vote
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).
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 at 22:42
add a comment |
up vote
1
down vote
up vote
1
down vote
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).
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).
edited Nov 19 at 10:39
answered Nov 18 at 23:49
progmatico
1,7061512
1,7061512
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 at 22:42
add a comment |
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 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 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 at 22:42
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
why is this tagged with
curl
?– hanshenrik
Nov 14 at 0:28
1
this is the format in the oops language curl
– Kamalapriya Subramanian
Nov 14 at 2:26
my concern is not about curl. I want to know how "shared" strategy solves diamond problem?
– Kamalapriya Subramanian
Nov 14 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 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 at 16:54