PATH
Table
of Contents
Previous
Section
In the first chapter, you created individual variables to store a guest's name, e-mail address, and comments. When keeping track of multiple guests, it's more useful to encapsulate all the data for a guest as a single entity. You'll do this by creating a Java class that contains the data for a single guest.
The newly created file contains a skeleton for a class called Guest.
import com.apple.yellow.foundation.*; import com.apple.yellow.eocontrol.*; import com.apple.yellow.webobjects.*; public class Guest extends EOCustomObject { protected String guestName; protected String email; protected String comments; Guest() { guestName = ""; email = ""; comments = ""; } }
Java classes require a constructor to initialize an instance (or object) of a particular class whenever one is created. A constructor has the same name as the class and returns no value.
Whenever your application creates a new Guest class, its instance variables are initialized with empty strings, which is the default value if the user enters no data. (If you prefer, you can use different strings for these initial values.)
Saving the file lets WebObjects Builder know about your newly created Guest class.
Table
of Contents
Next
Section
|
Copyright © 1998 Apple Computer, Inc. All rights reserved. |