SDSU CS 596 Client-Server Programming
Corba, Patterns, and Stuff

[To Lecture Notes Index]
San Diego State University -- This page last updated May 14, 1996

Contents of Corba, Patterns, and Stuff Lecture

  1. CORBA
  2. OpenDoc
  3. Tools
  4. What about C/C++ and Client-Server?


Common Object Request Broker Architecture
"CORBA allows applications to communicate with one another no matter where they are located or who has designed them"

Java Corba "like" Implementations

Black Widow
Sun (JOE and RMI)

Object Management Group (OMG)

Responsible for CORBA standard
Very Simple Bank Example
From Black Widow Web Pages

Contains balance which can be accessed

Used to provide access to bank account

Step 1 - IDL for classes

IDL = interface definition language
module Bank {

  interface Account {
    float balance();

  interface AccountManager {
    Account open(in string name);


Step 2

IDL to java compiler produces some java classes needed for CORBA

interface Bank.Account extends interface CORBA.Object 
interface Bank.AccountManager extends interface CORBA.Object 
class Bank._sk_Account implements interface Bank.Account 
class Bank._sk_AccountManager implements interface 
class Bank.Account_var 
class Bank.AccountManager_var 

Step 3 - Write Server CodeJava Server-Side Code

import java.util.*;

class Account extends Bank._sk_Account {

  private float _balance;

  Account(float balance) {
    _balance = balance;

  public float balance() throws CORBA.SystemException {
    return _balance;


More Server Code

class AccountManager extends Bank._sk_AccountManager {

  private Dictionary _accounts = new Hashtable();
  private Random _random = new Random();

  AccountManager(String name) {

  public Bank.Account open(String name) throws 
										CORBA.SystemException {

    // Lookup the account in the account dictionary.
    Bank.Account account = ( Bank.Account ) _accounts.get( name );

    if(account == null) {

      // Create a new account with between 0 and 1000 dollars.
      float balance = Math.abs(_random.nextInt()) % 100000 / 100f;
      account = new Account(balance);
      System.out.println("Created " + name + "'s account: " + account);

      // Export the new object reference.

      // Save the account in the account dictionary.
      _accounts.put(name, account);
    // Return the account.
    return account;

The Server
public class Server {

  public static void main(String[] args) {

    try {
      // Initialize some CORBA Stuff
      CORBA.ORB orb = CORBA.ORB.init();
      CORBA.BOA boa = orb.BOA_init();

      // Create the account manager object.
      AccountManager manager = 
        new AccountManager("Post-Modern Bank");

      // Export the newly create object.
      System.out.println(manager + " is ready.");

      // Wait for incoming requests
    catch(CORBA.SystemException e) {

Step 4 - Write the Client

public class Client {

  public static void main(String args[]) {
    try {
      // Initialize the ORB.
      CORBA.ORB orb = CORBA.ORB.init();

      // Locate an account manager.
      Bank.AccountManager manager = 
        Bank.AccountManager_var.bind("Post-Modern Bank");

      // use args[0] as the account name, or a default.
      String name = args.length > 0 ? args[0] : "Jack B. Quick";

      // Request the account manager to open a named account.
      Bank.Account account =;

      // Get the balance of the account.
      float balance = account.balance();

      // Print out the balance.
        ("The balance in " + name + "'s account is $" + balance);
    catch(CORBA.SystemException e) {

Step 5 Run Server and Client
prompt> java Client
The balance in Jack B. Quick's account is $71.62

prompt> java Client
The balance in Jack B. Quick's account is $71.62

prompt> java Client "Jack Sprat"
The balance in Jack Sprat's account is $322.38

prompt> java Client "Jack Sprat"
The balance in Jack Sprat's account is $322.38

prompt> java Client
The balance in Jack B. Quick's account is $71.62


The end of applications?


Patterns in Client-Server

From New Clients with Old Servers: A Pattern Language for Client/Server Frameworks by Wolf and Liu in Pattern Languages of Program Design ed. by Coplien, Schmidt 1995, Addison-Welsey
Built-in to Java

How to insure just one instance of a class

Objects From Records
Translate between flat relational rows of database to objects
Request object encapsulates network interface: TCP/IP, remote procedure calls, etc.

Move objects between server and client

Need to some action when object dies
Identity Management
Program is likely to materialize multiple copes of same object
Mega-Scrolling (virtual lists)
List of items which is too large to transport to client at one time
Dependency ( Model-View, Observer )
Keep interface code (view) separate from rest of program (Model)
How to create a Client handler in Server class without changing the server class
How to create interface and keep interface information from model
Complex windows can take too long to create
Cache windows and reuse them
Client/Server Framework

What about C/C++ and Client-Server?

See previous two slides