multiple inheritance
Wouter Verhelst
wouter at grep.be
Sun Jul 8 10:44:45 PDT 2012
"Namespace" <rswhite4 at googlemail.com> writes:
> How can i implement C++ behaviour like this:
>
> class Shape : Drawable, Transformable {
> class Sprite : Drawable {
> class Image : Transformable {
> ?
>
> One way is to declare Transformable or Drawable as interface.
> But what if i have more then one class which implements
> Transformable/Drawable and i wouldn't rewrite the implementation of
> Transformable/Drawable in every class again?
I see two options:
- Make both be an Interface, but also write classes
"DefaultTransformable" and "DefaultDrawable" which implement their
respective Interface from which you inherit; you can then choose which
of the two you reimplement and which of the two you inherit from.
- Make both be an Interface, and write some templates and/or mixins with
the default code that you import into child classes. That way it's
just a simple "mixin(functionFoo)" per method of the interface, or the
actual implementation if you don't want to "inherit".
Of course, you can also do both at the same time.
--
The volume of a pizza of thickness a and radius z can be described by
the following formula:
pi zz a
More information about the Digitalmars-d-learn
mailing list