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

Re: Good book on Dylan?



On Thu, 29 Mar 2001 19:00:02 -0500 (EST), "Mark Jordan"
<mark_jordan@nospam.ieee.org> wrote:

> Also if you could tell me how Dylan might cope with my
> interface/implementation problem I'd be most grateful.

Well, a simple answer might be that multiple-inheritance is easier in
Dylan. So you don't need to use object composition to avoid it.

e.g. (untested)

//
// Pantomime Interface
//

define abstract class <abstract-pantomime> ( <object> )
end;

define generic pantomime-actors ( o :: <abstract-pantomime> )
  => ( r :: <person-sequence> );

//
// Pantomime Implementation
//

define class <pantomime> ( <abstract-pantomime> )
  slot pantomime-actors :: <person-sequence>;
end;

//
// Horse Interface
//

define abstract class <abstract-horse> ( <object> )
end;

define generic horse-rider ( o :: <abstract-horse> )
  => ( r :: <person> );

//
// Horse Implementation
//

define class <horse> ( <abstract-horse> )
  slot horse-rider :: <person>;
end;

//
// Pantomime-Horse Interface
//

define abstract class <abstract-pantomime-horse>
  ( <abstract-pantomime>, <abstract-horse> )
end;

//
// Pantomime-Horse Implementation ( Composition )
//

define class <pantomime-horse> ( <abstract-pantomime-horse> )
  slot pantomime :: <pantomime> = make( <pantomime> );
  slot horse :: <horse> = make( <horse> );
end;

define method pantomime-actors ( o :: <pantomime-horse> )
  pantomime-actors( pantomime( o ) );
end;

define method horse-rider( o :: <pantomime-horse> )
  horse-rider( horse( o ) );
end;

//
// Pantomime-Horse Implementation ( Multiple Inheritance )
//

define class <pantomime-horse>
  ( <abstract-pantomime-horse>, <pantomime>, <horse> )
end;

Or something like that.

__Jason


Follow-Ups: References: