Oz and Mozart Users Mailing List

Re: Accreting features or attributes in object inheritance?


From: Alain Van Kerm (alain.van_kerm@etca.alcatel.be)
Date: Tue Sep 25 2001 - 14:16:54 CEST


Denys Duchier wrote:
>
> rlpowell@digitalkingdom.org (Robin Lee Powell) writes:
>
> > Lets say that class A defines a list:
> >
> > [ A B ]
> >
> > and puts that list in either an attribute or (preferrably) a feature.
> >
> > Now class B wants to extend that list without having to know anything
> > about what A put into it, so we have:
> >
> > [ A B C D ]
> >
> > Is there any way to do this?
>
> If you put the list in an attribute, you might do it as shown below,
> where my interpretation of your problem is that the list is `extended'
> at object-creation time. Notice how class B must explicitly invoke
> the initializer for class from which it inherits (this never happens
> automatically):
>
> declare
> class A
> attr list
> meth init list<-[a b] end
> meth getList($) @list end
> end
> class B from A
> meth init
> A,init
> list<-{Append @list [c d]}
> end
> end
>
> You cannot do it this way with a feature, since a feature is
> immutable. You might achieve it via a complex initialization
> protocol, but that's hardly worth the trouble.
>
> Cheers,
>
> --
> Dr. Denys Duchier Denys.Duchier@ps.uni-sb.de
> Forschungsbereich Programmiersysteme (Programming Systems Lab)
> Universitaet des Saarlandes, Geb. 45 http://www.ps.uni-sb.de/~duchier
> Postfach 15 11 50 Phone: +49 681 302 5618
> 66041 Saarbruecken, Germany Fax: +49 681 302 5615
> -
> Please send submissions to users@mozart-oz.org
> and administriva mail to users-request@mozart-oz.org.
> The Mozart Oz web site is at http://www.mozart-oz.org/.

class A
   feat list:[a b]
   meth init skip end
end

class B from A
   feat list:{Append {New A init()}.list [c d]}
   meth init
      A,init
   end
end

seems to work well too, if you can bear the creation of a temporary
object.

----------------------------------
Alain Van Kerm
  Alcatel ETCA - TEL/NM Department
----------------------------------
-
Please send submissions to users@mozart-oz.org
and administriva mail to users-request@mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.



This archive was generated by hypermail 2b29.