Article View: comp.lang.misc
Article #3370Re: CHALLENGE: heterogeneous collections
From: Richard Bielak
Date: Wed, 03 Apr 1991 21:14
Date: Wed, 03 Apr 1991 21:14
54 lines
2414 bytes
2414 bytes
In article <CIMSHOP!DAVIDM.91Apr1224716@uunet.UU.NET> cimshop!davidm@uunet.UU.NET (David S. Masterson) writes:
[...]
>
>I really hate the idea of contradicting Bertrand Meyer as I'm probably getting
>in over my head.
Don't blame you! :-)
[...]
>On the other hand:
>
> h_collection: COLLECTION [void] /* or is it 'void*'? */
>
>might be a *truly* heterogeneous collection (assuming objects entered into the
>collection can be implicitly cast to VOID), but (going back to the original
>question) how useful would it be since all clues as to type and protocol of
>objects in the collection are removed?
The generic collection should really be declared as:
h_collection: COLLECTION [ANY];
as any class in Eiffel is an heir of ANY.
The following trick can be used to do things with objects in such
a collection.
my_weird_object : MY_WEIRD_CLASS;
....
my_weird_object ?= h_collection.next_item;
-- above line gets the next item from the collection
-- and does a "reverse" assigment to my variable.
-- this assigment will only work, if the type on
-- the right is of type MY_WEIRD_CLASS (or a descendant)
-- otherwise, Void is returned.
-- so,
if not my_weird_object.Void then
-- got a weird_object_here, do what you need to
....
end;
...richie "What does a virtual void look like?"
--
*-----------------------------------------------------------------------------*
| Richie Bielak (212)-815-3072 | Programs are like baby squirrels. Once |
| Internet: richieb@bony.com | you pick one up and handle it, you can't |
| Bang: uunet!bony1!richieb | put it back. The mother won't feed it. |
Technical Details
Message-ID:
<1991Apr3.211414.25628@bony1.bony.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!bony1!richiebReferences:
<1991Mar25.220525.11087@leland.Stanford.EDU> <CIMSHOP!DAVIDM.91Mar28192651@uunet.UU.NET> <521@eiffel.UUCP> <CIMSHOP!DAVIDM.91Apr1224716@uunet.UU.NET>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!bony1!richieb From: richieb@bony1.bony.com (Richard Bielak) Newsgroups: comp.lang.misc,comp.object Subject: Re: CHALLENGE: heterogeneous collections Message-ID: <1991Apr3.211414.25628@bony1.bony.com> Date: 3 Apr 91 21:14:14 GMT References: <1991Mar25.220525.11087@leland.Stanford.EDU> <CIMSHOP!DAVIDM.91Mar28192651@uunet.UU.NET> <521@eiffel.UUCP> <CIMSHOP!DAVIDM.91Apr1224716@uunet.UU.NET> Reply-To: richieb@bony1.UUCP (Richard Bielak) Distribution: comp Organization: Bank of New York Lines: 54