Applying contracts to abstract base class?

From: Ken (kk_oop_at_yahoo.com)
Date: 10/27/03


Date: 27 Oct 2003 05:12:08 -0800

Hi. I'm looking to find a way to apply Design by Contract in my C++
programs.

The problem that I'm having deals with interface base classes (a base
class with only pure virtual methods). Since these are often how an
object gets exposed to clients via polymorphism, it seems critical
that an abstract base class can define and enforce its contracts.
Defining contracts is critical, so LSP can
be utilized when defining derived implementation classes. However, if
the interface base class defines a method to enforce its contract, it
will no longer be an abstract interface. This poses a problem, for
instance, if the abstract class is being used to apply multiple
interface inheritance. In that case, the abstract class really needs
to be pure abstract, otherwise it will result in having multiple
implementation inheritance, which, in C++, is a risky, undesireable
design.

Is there a way for C++ to somehow enable an interface base class to
enforce its contracts? Seems like an unfixable paradox.

Any thoughts?

Thanks,

Ken



Relevant Pages

  • Re: Language enhancements
    ... > In design by contract as defined by Eiffel, contracts are inherited. ... > And there are a few simple but very precise rules about how subclasses ... > can alter the contracts that they inherit. ... Should everything that holds for a base class also ...
    (borland.public.delphi.non-technical)
  • Re: Language enhancements
    ... A base class that provides a virtual method must account for that in its ... If you find it necessary, in creating a descendant, to nullify ... code implemented by the ancestor, then that code should not be in the ... Same applies to contracts; descendants should not break ancestor contracts, ...
    (borland.public.delphi.non-technical)