RE: Delegation syntax? (was: Re: Private contracts)

2002-10-04 Thread Garrett Goebel

John Williams:
 Reaction #2:  Inheritance would automatically delegate all those
 methods, so again, in what way does inheritance _not_ solve 
 the problem?

What about when you want to be able to dynamically swap the objects to which
you're delegating?

--
Garrett Goebel
IS Development Specialist

ScriptPro   Direct: 913.403.5261
5828 Reeds Road   Main: 913.384.1008
Mission, KS 66202  Fax: 913.384.2180
www.scriptpro.com  [EMAIL PROTECTED]



Re: Delegation syntax? (was: Re: Private contracts)

2002-10-03 Thread John Williams

On Thu, 3 Oct 2002, Michael Lazzaro wrote:

 1) Delegation through inheritance:
   (a.k.a. mixin classes, hard delegation, concrete interfaces,
 etc., etc.)

   Example: I want to say that a class DataManager has the capabilities
   of the interfaces DataStrategy and CacheStrategy, but is not strictly a
   subclass of either.  In other languages, this might appear like:

   class DataManager implements DataStrategy, CacheStrategy { ... }
   - or -
   class DataManager mixin DataStrategy, CacheStrategy { ... }

Aside from runtime mixin', in what way does inheritance _not_ do what you
want?

 2) Delegation through attribute:
   (a.k.a soft delegation, instance-based delegation, etc., etc.)

   The ability to specify that, if an instance of an object DataSnippet
   is affiliated with a specific, runtime instance of a DataManager, e.g.

   class DataSnippet {
   attr $data_manager is DataManager;
   }

   ... then [some, all] public methods of $self.data_manager can
   automatically be delegated by the DataSnippet to that specific
   instance, eliminating the need for code that makes you want
   to kill yourself:

   method foo (...) { $self.data_manager.foo( ... ) }
   method bar (...) { $self.data_manager.bar( ... ) }
   # ... repeat until carpel tunnel syndrome sets in ...

Reaction #1:  Only on a perl list would it occur to people to complain
about that.  :)

Reaction #2:  Inheritance would automatically delegate all those
methods, so again, in what way does inheritance _not_ solve the problem?


Finally, a question about interfaces:
In what way is an interface different from a pure abstract class (i.e.
containing only method declarations, but no code)?

~ John Williams

DISCLAIMER: This post assumes perl6 will have multiple inheritance.





Re: Delegation syntax? (was: Re: Private contracts)

2002-10-03 Thread Michael G Schwern

On Thu, Oct 03, 2002 at 07:59:33PM -0600, John Williams wrote:
 Reaction #2:  Inheritance would automatically delegate all those
 methods, so again, in what way does inheritance _not_ solve the problem?

I don't think p6l is the right place to discuss the merits of delegation,
let's just say it's a Good Thing to have in your OO toolbelt.  Solves a lot
of problems which would otherwise require hairy, ambiguous multiple
inheritance situations.  If you're curious I can explain more off-list.


 Finally, a question about interfaces:
 In what way is an interface different from a pure abstract class (i.e.
 containing only method declarations, but no code)?

An interface requires subclassers to implement all abstract methods and they
must match the method signatures, conditions and invariants of the
interface.

A pure abstract class doesn't necessarily require subclasses to do anything,
at least not in Perl.

So an interface is simply a class, maybe abstract, which requires its
subclasses to conform to its signature.

At least that's how I see it.


-- 

Michael G. Schwern   [EMAIL PROTECTED]http://www.pobox.com/~schwern/
Perl Quality Assurance  [EMAIL PROTECTED] Kwalitee Is Job One
It's Airplane Glue sniffing time!