Next Previous Up Top Contents Index

5.4 Defining the interfaces

5.4.1 Initializing and exiting account frames

Each time we make a new account interface we want to ensure two things:

An easy way to do this is to add aninitialize-instance after method specialized onaccount-interface. (In Common Lisp, each call to make an instance of a given class is automatically followed by a call to initialize that instance; you are free to specialize theinitialize-instance generic function on particular classes.)

(defmethod initialize-instance :after ((self account-interface)     &key)
  (with-slots (account-ref balance-field) self
    (when account-ref
      (setf (capi:display-pane-text balance-field)
            (format nil "~A" (op:balance account-ref))))))

Here, we encounter our first example of invoking a CORBA operation on a CORBA object. The Common Lisp variableaccount-ref, of classBankingDemo:account, contains a proxy for a CORBAaccount object on the server. The application(op:balance account-ref) invokes a stub method specialized on the proxy's class. The stub method forwards the request across the ORB to the actual object on the server.

The request is executed on the object in the server and the result passed back across the ORB to the stub method, which returns the value to the client as acorba:long. This value is then used to set the initial value of thebalance field.

We can initialize the interface for a checking account in a similar way:

(defmethod initialize-instance :after (
     (self checking-account-interface)  &key)
  (with-slots (account-ref limit-field) self
    (when account-ref
      (setf (capi:display-pane-text limit-field)
            (format nil "~A" (op:limit account-ref))))))

Inheritance ensures that the method onaccount-interface is called which registers the interface and sets up itsbalance field; a call to theop:limit stub determines the initial value of itslimit field.

For convenience, we define a generic functionmake-account-frame that makes the correct class of frame for a givenaccount object reference:

(defmethod make-account-frame ((self BankingDemo:account) 
                                &key bank-interface title)
  (push-new-item bank-interface
                 title
                 (make-instance 'account-interface 
                                :account-ref self
                                :account-name title
                                :owner bank-interface)))
(defmethod make-account-frame ((self BankingDemo:checkingAccount)
                                &key bank-interface title)
  (push-new-item bank-interface
                 title
                 (make-instance 'checking-account-interface 
                                :account-ref self
                                :account-name title
                                :owner bank-interface)))

These methods simply dispatch on the class of the object reference to make anaccount-interface orcheckingAccount-interface as appropriate.


Developing Component Software with CORBA - 22 Jan 1999

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker