home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.object:3034 comp.lang.eiffel:996
- Path: sparky!uunet!mcsun!Germany.EU.net!unido!donald!support
- From: support@heeg.de (Support)
- Newsgroups: comp.object,comp.lang.eiffel
- Subject: Re: Class methods (was: Re: How to design a data structure library)
- Message-ID: <1992Jul28.121706.25213@heeg.de>
- Date: 28 Jul 92 12:17:06 GMT
- References: <1992Jul21.124256.17256@bony1.bony.com> <1992Jul22.142916.22115@merlin.hgc.edu> <1992Jul23.123609.11699@bony1.bony.com>
- Organization: Georg Heeg Objektorientierte Systeme, Dortmund, FRG
- Lines: 47
-
- In article <1992Jul23.123609.11699@bony1.bony.com> richieb@bony1.bony.com (Richard Bielak) writes:
- >In article <1992Jul22.142916.22115@merlin.hgc.edu> jcm@hgc.edu (James McKim) writes:
- >
- >[...]
- >
- >The interesting question is which class should the routine "union" be
- >in? If a, b, and c are of type SET and "union" is a feature of SET,
- >then we have:
- >
- > c := a.union(a,b);
- >
- >Which looks a little odd :-).
- >
- >In Smalltalk lingo, "union" should be a "class method". The essence of
- >a class method is that it can be invoked when the object of the given
- >class does not exist yet.
-
- Is it? I always thought the essence of a class method is that you can sent it
- to a class object... Thus, class methods are nothing special since classes
- are nothing special. Just that you don't have them at all in C++ :-)
-
- "union" would be a normal instance method, like
-
- c := a union: b.
-
- or better:
-
- c := a mergeWith: c
-
- or even better:
-
- c := a + b.
-
- BTW, in standard Smalltalk there is no "union", "intersection", or "difference".
- You'd have to implement it as follows:
-
- c := a addAll: b "union"
- c := a select: [:each | b includes: each] "intersection"
- c := a removeAll: b. "difference"
-
- Ciao, Hasko
-
- --
- +-------------------------------------------------------+
- | Hasko Heinecke @ Georg Heeg Objektorientierte Systeme |
- | I _never_ mean what I say - and nobody else does... |
- +-------------------------------------------------------+
-