ListManager Model Classes
The ListManager
web application uses a User
object to model a mailing list
subscriber and her mail delivery preferences. The User
class does not have a public
constructor, however. Instead, User
objects are returned from a UserFactory
object, which uses a database
backend to provide a persistent store for subscriptions and delivery
preferences. The four public methods of UserFactory
are:
insert( )
Adds a subscription to the database and returns a
User
object for itselect( )
Looks up the
User
object that corresponds to a specified email address and passwordupdate( )
Updates email delivery preferences in the database to match the current state of the specified
User
objectdelete( )
Deletes a subscription from the database, unsubscribing the specified
User
from the mailing list
Note that these four methods are named after the SQL statements
they each use. The source code for User
and UserFactory
are listed in Examples Example 20-7 and Example 20-8.
Example 20-7. User.java
package je3.servlet; /** * This class represents a mailing list subscriber. * It has JavaBeans-style property accessor methods. */ public class User { String email; // The user's e-mail address boolean html; // Whether the user wants HTML-formatted messages boolean digest; // Whether the user wants digests boolean deleted; // Set by UserFactory.delete( ); tested by insert( ) // The constructor is package-private. // See UserFactory for public methods to obtain a User object. User(String email, boolean ...
Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.