From: richieb@bony1.bony.com (Richard Bielak)
Subject: Re: views and dynamic binding
Keywords: help, example in meyer's book (pg 272 in my version)
Organization: multi-cellular
Date: Thu, 9 Apr 92 12:31:56 GMT

In article <Apr.7.18.06.34.1992.29333@aramis.rutgers.edu> partha@aramis.rutgers.edu (a_zombie) writes:
>
>This is related to the example given in the book (OOS/W Construction).
>The example talks about how to create different 'views' ( in database sense)
>of the same data structure using exports and inheritance:
>
>It defines a class bank_account with all the procedures but without exporting 
>any, different views like clerk_view,customer_view etc are direct children 
>of the class bank_account with different exports.
>
>Now suppose in one top level class ( like session) i need to have different
>views of the a same account:
>
>I am confused about how to do it:
>
>first of all when i create a new account: should i create a bank_account entity
>or a manager_view entity  or  a customer_view entity? Basically it is not clear
>to me how different views could be refered to the same account object.
>

Using the inheritance hierarchy from the book example, you would have
to create a CLERK_VIEW or CUSTOMER_VIEW object.


>Perhaps reverse assignment attempt will be useful here: create the account as 
>bank_account type and reverse assign to different views.
>Then the routines in session has to  be written in terms of the class 
>type  to which it dynamically binds after the reverse assignment to satisfay 
>static type checking of eiffel.  Is this the correct
>way to do it?  Am I missing some simple things?
>

Reverse assigment would not work here. Because object of type
BANK_ACCOUNT is not of type CLERK_VIEW - reverse assigment would just
give you "Void".

I think that the inheritance hierarchy of this example is wrong. It's
upside down. It should be like this:


       CLERK_VIEW      CUSTOMER_VIEW      MANAGER_VIEW
           ^                ^                  ^
           |                |                  |
           \                |                  /
            \               |                 /
             \              |                /
              \             |               /
               ----   BANK_ACCOUNT  -------



Then you create BANK_ACCOUNT objects, and then assign it to entities
of the type you want. So, the code might look like this:


            account : BANK_ACCOUNT;

            c_acct : CLERK_VIEW;

            ...

            account.Create;
            c_acct := account; -- now you get clerk's view through
                               -- the "c_acct" entity.
            

I hope this answers your question.


...richie


P.S. It feels funny to disagree with OOSC , I hope I didn't put my
     foot in my mouth. :-)

P.P.S. This example also shows a non-trivial use of
       multiple-inheritance.
-- 
* Richie Bielak   (212)-815-3072   | "Your brain is a liquid-cooled parallel  *
* Internet:       richieb@bony.com | super-computer". He pointed to his nose, *
* Bang {uupsi,uunet}!bony1!richieb | "This is the fan."                       *
*    - Strictly my opinions -      |                     - David Chudnovsky - *
Newsgroups: comp.lang.eiffel