[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: External (C++) interfaces



   Date: Fri, 1 Dec 95 09:31:39 EST
   From: Mike Griebling <grieblm@trt.allied.com>

   [...]
   What is an interface type? 

The `interface' concept allows greater flexibility in (single-
inheritance) class design without having to resort to multi-
inheritance a la C++.  Objective-C and Java feature this.  

I'll try to explain this by example.  Imagine you want some classes to
incorporate the attribute `Printable', ie these classes have a
type-bound procedure `ConvertForPrint' that produces output that can
be send to the printer.  Then a procedure `Print' takes a collection
of printable objects, converts them for the printer, arranges them on
the page, and finally prints them.  
  In Oberon-2 this `collection of printable objects' has to be a set
of objects derived from the single class `Printable', due to the O2
type rules.  This means that all `Printable' classes have to form a
subtree of your class lib, which is very restrictive.
  In Objective-C (or Java) you can define `Printable' as an interface,
describing the type-bound procedures that have to be defined in a
particular class to implement this interface.  A class definition has
to state which interfaces it's implementing (eg, "class Circle
implements Printable;") and provide the necessary type-bound procs.
An interface `I' can be used like any type, eg  to declare a variable.
Then all objects whose classes implement `I' can be assigned to such a
variable.  This means that the above `collection of printable objects'
is a set of objects that implement the `Printable' interface, the
objects' classes can be from anywhere inside your (single-inheritance)
class library.  

I hope you get the idea.  Otherwise you may take a look at the
Objecte-C or Java docs on the net.

-- mva