Topic: about dynamic inheritance...
Author: brangdon@cix.co.uk (Dave Harris)
Date: Fri, 22 Mar 2002 19:25:46 GMT Raw View
junior_s@sympatico.ca (Serafim Fagundes) wrote (abridged):
> Real dynamic inheritance should look like this:
> [...]
> class Derived : public Base2;
In what sense is it "dynamic"? Your example seems to fix all the details
of Derived at compile-time.
Your email to me included a template example which is already legal. Eg:
template <typename T>
class Derived : public T { ... };
class Base1 { ... };
class Base2 { ... };
Derived<Base1> d1;
Derived<Base2> d2;
Now we can write Derived without deciding which base class to use until
later. Did you know this was legal? If so, how does it differ from what
you want? Does multiple inheritance help?
Dave Harris, Nottingham, UK | "Weave a circle round him thrice,
brangdon@cix.co.uk | And close your eyes with holy dread,
| For he on honey dew hath fed
http://www.bhresearch.co.uk/ | And drunk the milk of Paradise."
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: brangdon@cix.co.uk (Dave Harris)
Date: Fri, 22 Mar 2002 13:28:21 CST Raw View
marco@technoboredom.net (Marco Manfredini) wrote (abridged):
> > It is not "proper" inheritance, in that overriding
> > doesn't work for self-sends. Eg if Base::method1() calls method2(), it
> > will see its own definition, not the definition in Derived.
>
> Depends on what <assignment to a member which has been declared a
> "inheritance" member> means. It could include an adjustment to the
> vtable (or whatever) to make method2 point to Derived::method2.
I've recovered my copy of D&E; this is section $12.7 under the title
"Delegation". Stroustrup explicitly says that "Functions in the delegating
class do not override functions of the class delegated to."
Dave Harris, Nottingham, UK | "Weave a circle round him thrice,
brangdon@cix.co.uk | And close your eyes with holy dread,
| For he on honey dew hath fed
http://www.bhresearch.co.uk/ | And drunk the milk of Paradise."
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Serafim Fagundes" <junior_s@sympatico.ca>
Date: Sat, 23 Mar 2002 20:52:01 GMT Raw View
> template <typename T>
> class Derived : public T { ... };
>
> class Base1 { ... };
> class Base2 { ... };
>
> Derived<Base1> d1;
> Derived<Base2> d2;
>
> Now we can write Derived without deciding which base class to use until
> later. Did you know this was legal? If so, how does it differ from what
> you want? Does multiple inheritance help?
....I didnt know it was legal...
This dynamic inheritance idea will sleep... for now.
I think that it might be a good tool for domains like biology, where some
elements(I'm not a biologist, by the way, but have some interests in
biology) might inherit behaviors(data or whatever...) from an other element
or elements (of a certain group), without knowing how many of these elements
will be inherited.
It is easy to do with interpreted languages, but when it comes to compiled
languages, things get harder. To design and to implement.
Like I said, dynamic inheritance would bring a new paradigm to C++PL. A kind
of superset to OOP.
That's all folks. Thank you very much!
--
Serafim Fagundes
Montr al, Qu bec, Canada
serafimfagundes@hotmail.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Serafim Fagundes" <junior_s@sympatico.ca>
Date: Tue, 19 Mar 2002 09:24:04 GMT Raw View
Hi, all! I'm working on a project and a crazy idea struct me. Dynamic
Inheritance. OK. Good idea and of course someone else has thought of it. I'm
interested in knowing if someone in the commitee migth have spoke of the
possibilities and the new powers that it could bring to a language like C++.
There are a few extentions available to the C++ and Java languages but stil
it aint really Dynamic Inheritance.
Personaly it think it would bring a new level( or missing level??? ) to the
C++ paradigm.
I dont know really who to ask( except maybe Bjarne by email... ), so I try
it here.
What do you think about it?
--
Serafim Fagundes
Montr al, Qu bec, Canada
serafimfagundes@hotmail.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Marco Manfredini <marco@technoboredom.net>
Date: Tue, 19 Mar 2002 17:36:50 GMT Raw View
"Serafim Fagundes" <junior_s@sympatico.ca> wrote:
> Hi, all! I'm working on a project and a crazy idea struct me. Dynamic
> Inheritance. OK. Good idea and of course someone else has thought of
> it. I'm interested in knowing if someone in the commitee migth have
> spoke of the possibilities and the new powers that it could bring to a
> language like C++. There are a few extentions available to the C++ and
> Java languages but stil it aint really Dynamic Inheritance.
What exactly do you mean by "dynamic inheritance"?
template<class T>
class X : T
{
};
or some kind of runtime-dependent scheme where you can assign a delegate,
like:
class I : public SomeInterface
{
public:
void foo();
};
class X
{
public:
inherits SomeInterface *si;
X() si(new I()) {}
void morph() { <replace *si with another instance> }
};
X x;
x.foo(); // does x.si->foo() due to the "inherits" tag;
??
Details please. Critique may follow then.
--
Marco
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Serafim Fagundes" <junior_s@sympatico.ca>
Date: Wed, 20 Mar 2002 15:50:08 GMT Raw View
I might have asked this question at the worsetest moment in my schedule...
and my English is so bad!
This question has given me more than a hundred new questions. Dynamic
Inheritance? What new possibilities would it offer? All I saw was a new
language and a new paradigm. It might be possible to make the ajustments to
the C++PL, but it might raise a ruckus. (if anyone is interested we can
discuss about it... see email at the end!)
> What exactly do you mean by "dynamic inheritance"?
>
> template<class T>
> class X : T
> {
> };
This is interesting! But what happens if I need to inherit from more than
one class?
// would I need to do that?
template<class T1, class T2>
class X: public T1, T2 {
};
// I dont like it! I think all classes should implicitly be able to inherit
// dynamically any classes available!
more below...
> or some kind of runtime-dependent scheme where you can assign a delegate,
> like:
>
> class I : public SomeInterface
> {
> public:
> void foo();
> };
>
> class X
> {
> public:
> inherits SomeInterface *si;
> X() si(new I()) {}
> void morph() { <replace *si with another instance> }
> };
>
> X x;
> x.foo(); // does x.si->foo() due to the "inherits" tag;
>
> ??
> Details please. Critique may follow then.
>
> --
> Marco
>
Well, the "inherits" tag is also interesting!
I would like something like this:
class X : public SomeInterface
{
};
// could be the same as
X::inherits = public SomeInterface;
// or
inherits X : public SomeInterface;
// where "inherits" could be a kind of ptr to the vtable (or something like
// the virtual vtable...)
// ...and another class could be "imposed" like this
X::imposed = public SomeOtherInterface;
// or
imposed public SomeOtherInterface ;
// ...would be the same as this
X::inherits += public SomeOtheInterface;
My question was more from a design point of view than from a language. It
would be easy with an interpreted language but with a compiled language,
like C++, it might not be ideal unless with the RTTI . . . . It would be
interesting to see a language like C++ to offer another programming
scheme(object-oriented, generic and _I_not_sure_yet_).
confused!
--
Serafim Fagundes
Montr al, Qu bec, Canada
serafimfagundes@hotmail.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: brangdon@cix.co.uk (Dave Harris)
Date: Thu, 21 Mar 2002 16:41:32 GMT Raw View
junior_s@sympatico.ca (Serafim Fagundes) wrote (abridged):
> Hi, all! I'm working on a project and a crazy idea struct me. Dynamic
> Inheritance. OK. Good idea and of course someone else has thought of
> it.
I am not sure what you mean. A form of dynamic inheritance is discussed in
Stroustrup's book, "Design and Evolution of C++". I don't have a copy to
hand so I can't give a more exact reference. As I recall, he tried it with
a syntax like:
class Base {
public:
virtual void method1();
virtual void method2();
};
class Derived: public *p {
Base *p;
public:
virtual void method2();
// ...
};
Derived d;
d.method1(); // calls d.p->method1();
where the instance variable 'p' can be assigned to at run-time. Is this
what you mean? It is not "proper" inheritance, in that overriding doesn't
work for self-sends. Eg if Base::method1() calls method2(), it will see
its own definition, not the definition in Derived.
Dave Harris, Nottingham, UK | "Weave a circle round him thrice,
brangdon@cix.co.uk | And close your eyes with holy dread,
| For he on honey dew hath fed
http://www.bhresearch.co.uk/ | And drunk the milk of Paradise."
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Serafim Fagundes" <junior_s@sympatico.ca>
Date: Thu, 21 Mar 2002 21:46:26 GMT Raw View
This one obsoletes the first reply sent (by accident, sorry) to Dave
Harris.
----------------------------------------------------------------------------
---
If stand in a design or physical point of view, it would be interesting to
have
classes inherit dynamically from another class.
Understand that dynamic inheritance can add a new paradigm to the C++.
Derived classes wouldn't be pre-designed to inherit. Also, being able to
inherit dynamically from any other class (available), changes our
perspective of object-oriented design.
> I am not sure what you mean. A form of dynamic inheritance is discussed in
> Stroustrup's book, "Design and Evolution of C++". I don't have a copy to
I do remember seeing a Inherited keyword in D&E but cant comment on that not
having a copy also...
> hand so I can't give a more exact reference. As I recall, he tried it with
> a syntax like:
>
> class Base {
> public:
> virtual void method1();
> virtual void method2();
> };
>
> class Derived: public *p {
> Base *p;
> public:
> virtual void method2();
> // ...
> };
>
> Derived d;
> d.method1(); // calls d.p->method1();
>
> where the instance variable 'p' can be assigned to at run-time. Is this
> what you mean? It is not "proper" inheritance, in that overriding doesn't
> work for self-sends. Eg if Base::method1() calls method2(), it will see
> its own definition, not the definition in Derived.
well the example isnt really dynamic inheritance it is passed as inheritance
but then kept as a composite... its not good. Real dynamic inheritance
should look like this:
class Base1;
class Base2;
class Derived : public Base1;
// Derived inherits Base1 behaviors (or member methods).
Derived d1;
// A Derived object is constructed. d1 offers what Derived and Base1
publicly offers.
d1.dowhatever();
// ...
// d1 stays the way it was conceived i.e.: from the same class with the same
base class, if any.
// OH,OH!
class Derived : public Base2;
// New class Derived but this time its Base2;
Derived d2;
// :) you know whats inside!
// But this would be an error!
d1=d2; // error. Chances are they are not the same.
// More interesting!
class Derived : public Base1, public Base2;
I stop here for the moment. The C++PL and OOP could benefit from this, but I
still think it should be used with a new paradigm (added with the others
already available in C++).
....or am I missing something?
--
Serafim Fagundes
Montr al, Qu bec, Canada
serafimfagundes@hotmail.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Marco Manfredini <marco@technoboredom.net>
Date: Thu, 21 Mar 2002 22:23:33 GMT Raw View
brangdon@cix.co.uk (Dave Harris) wrote:
> where the instance variable 'p' can be assigned to at run-time. Is this
> what you mean? It is not "proper" inheritance, in that overriding
> doesn't work for self-sends. Eg if Base::method1() calls method2(), it
> will see its own definition, not the definition in Derived.
Depends on what <assignment to a member which has been declared a
"inheritance" member> means. It could include an adjustment to the vtable
(or whatever) to make method2 point to Derived::method2. Which gives us the
really nasty problems then: To allow proper destruction, the Base's vtable
has to restored upon destruction *or* assignment to Derived::p. Precautions
must be taken to prevent one instance of Base to be base object of two
*different* instances (or a clever way of determination must be found to
support this, eh, virtual dynamic inheritance)...etc..pp
I any case we'd need some new kind of pointers (with complicated lifetime
considerations etc.) to implement dynamic inheritance. I'd rather see the
benefits of DI before doing this.
--
Marco
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]