Putting controller logic in a regular Java class.

Enterprise Java
Architecting and Designing Scalable, Multitier Systems
by Michael Minh Nguyen
Listing 3. Putting controller logic in a regular Java class.


package com.scalablemultitier;

public class UserController
{
  // 1. Implement controller logic to create beans such as session
  // bean, EJBs, and regular beans as needed to register the user.
  // 2. return User bean if successful. Return null if failed.
  public User registerUser (String firstName, String middleInitial,
    String lastName, String email)
  {
    User user = null;
    try
    {
      user = new User ();
      user.setFirstName (firstName);
      user.setMiddleInitial (middleInitial);
      user.setLastName (lastName);
      user.setEmail (email);
      // Provide system-specific logic here to save User such as
      // creating a session bean
      // that save User to the database.
    }
    catch (Exception exception)
    {
      // perform error processing here
    }
    return user;
  }
}

About the Author

Michael Minh Nguyen is a senior software engineer at eBuilt Inc. in Irvine, CA. He may be contacted at [email protected].