Re: interface question



Joanna... Again. I just disagree. IRoadVehicle and RoadVehicle are
functionally
equivalent in C++. The fact that you must use IRoadVehicle is simply a
limitation of C# since C# does not support multiple inheritance of
implementation. IRoadVehicle is simply a syntax construct for languages
that
support single inheritance of implementation and multiple inheritance of
pure
virtual classes (interfaces). An AmphibiousVehicle certainly is a road
vehicle
and is certainly a water vehicle. Both are specializations of vehicle
and there
is no reason why a vehicle cannot inherit or display characteristics of
both. A
modern canon can be fired and loaded, but not loaded and fired at the
same
time (hopefully). Inheritance can add behaviour. There is no reason why
a
person cannot inherit from eater and talker and not be able to eat and
talk at
the same time... although some of my friends _are_ able to do this.

Any discussion of the most basic concepts of OOP should be valid across
languages. If you truly feel that IRoadVehicle and RoadVehicle are
functionally
different then please show the code in C++ that demonstrates a
significant
functional difference other than the fact that IRoadVehicle has no
implementation.

So to summarize my argument. Interfaces and inheritance both represent
IS_A
relationships. Interfaces are a syntax construct that represents a
subset of
IS_A relationships, the pure virtual class. Containment represents HAS_A
relationships. MULTIPLE INHERITANCE represents LIKE_A relationships. So
IS_A and LIKE_A are not mutually exclusive concepts.

In C++ there is no distinction between multiple inheritance of
implementation and multiple inheritance of pure virtual classes. If you
have a
class that can be shared across classes, a so called mix in class, then
it
represents a LIKE_A relationship. Such a class can have implementation
details in C++. So in C++ a class with implementation details or a class
without implementation details can represent a LIKE_A relationship. So
in
C++ any non final class can represent a LIKE_A relationship. In C# only
pure
virtual classes can be inherited in this manner, so in _C#_ only
interfaces can
represent a LIKE_A relationship. Interfaces and base classes in C#
represent
IS_A relationships. Interfaces in C# can also represent LIKE_A
relationship.
Base classes in C# cannot represent a LIKE_A relationship. In C++ there
is no
need to distinguish between base classes and interfaces (pure virtual
classes)
since C++ supports multiple inheritance of implementation.

Regards,
Jeff
class AmphibiousVehicle : Vehicle, IRoadVehicle, IWaterVehicle

....is more accurate than saying

class AmphibiousVehicle : RoadVehicle, WaterVehicle


*** Sent via Developersdex http://www.developersdex.com ***
.



Relevant Pages

  • Re: Java Feature Proposal
    ... > conflict. ... No, there is no naming conflict with Java interfaces, since they contain ... class to inherit multiple conflicting implementations of a method. ... I don't see why multiple inheritance of fields is any more of a problem ...
    (comp.lang.java.programmer)
  • Re: Java Feature Proposal
    ... implementation of interfaces. ... multiple inheritance of fields which was the only big problem of [poorly ... > classes can provide the same functionality as you're proposing. ... Yes abstract base classes could be used similarly except that you can't have ...
    (comp.lang.java.programmer)
  • Re: IDropSource and IDataObject Multiple Inheritance
    ... COM does not support multiple inheritance for interfaces. ... apartment model of the object and the apartment model of the ... One of this is invoked by ActiveXContainer and anothere by WindowsShell. ...
    (microsoft.public.win32.programmer.ole)
  • Re: Former C++ Programmer Approaches Lisp
    ... >> multiple inheritance but this is as close as we can get. ... > I think this is an overly simplistic way to view interfaces. ... Interfaces compromise by not allowing state to ... interfaces can only contain abstract methods. ...
    (comp.lang.lisp)

Loading