Abstract interfaces

Instructor's Guide


intro, types, algebra, modules, classes, summary, Q/A, literature
When choosing for the module realization of the data abstraction list in C style, we are likely to have an abstract functional interface as specified in slide mod-face.

Modules -- a functional interface

ADT


  typedef int element; 
  struct list;
  
  extern list* nil();
  extern list* cons(element e, list* l);
  extern element head(list* l);
  extern list* tail(list* l);
  extern bool equal(list* l, list* m);
  

slide: Modules -- a functional interface

For convenience, the list has been restricted to contain integer elements only. However, at the expense of additional notation, we could also easily define a generic list by employing template functions as provided by C++. This is left as an exercise for the reader. The interface of the abstract class list given in slide obj-face has been defined generically by employing templates.

Objects -- a method interface

OOP


  template< class E > 
  class list {
  public:
  list() { }
  virtual ~list() { }
  virtual bool empty() = 0;
  virtual E head()  = 0;
  virtual list<E>* tail() = 0;
  virtual bool operator==(list<E>* m) = 0;
  };
  

slide: Objects -- a method interface

Note that the equal function in the ADT interface takes two arguments, whereas the operator== function in the OOP interface takes only one, since the other is implicitly provided by the object itself.