Comparing Two Design Ideas

I am developing an online service and I need to validate users and process text messages. I have two ideas for this. Can you tell me which idea you think is better and more OO?

1) Create a User object to validate the packet's sender every time I receive a packet. The User object will be forgotten after the verification is done by garbage collection. Create a Message object to process a message every time a text message packet is received. The Message object will be forgotten like the User. The User will verifyitself and the Message will processitself.

Example:

class User{

public User(String userID){

...

}

publicvoid validateYourself(){

...

// queries MySQL database for this ID and validates the user

}

}

class Message{

public Message(String from, String message){

...

}

publicvoid processYourself(){

...

}

}

2) Create a UserManager object and a MessageManager object when the program starts. The UserManager and MessageManager will stay alive for the duration of the program. The UserManager will validateany user and the MessageManager will validateany message.

Example:

class UserManager{

public UserManager(){

...

}

publicvoid validateUser(String id){

...

}

}

class MessageManager{

public MessageManager(){

...

}

publicvoid processMessage(String from, String msg){

...

}

}

[2746 byte] By [ktm5124a] at [2007-10-2 21:08:12]
# 1

Hard to tell, based on what you've posted.

If your app requires that users be validated, I'd say there should be a security feature that puts their credentials into session once they've logged in. Do it once. Have a timeout for the session and make sure you clean up when the session dies.

I don't know what "process message" looks like. I'd imagine that you'd be persisting messages as the user posted them. But I'd have a MessageDAO that would take care of that. All your database code belongs in a persistence layer.

%

duffymoa at 2007-7-13 23:53:59 > top of Java-index,Other Topics,Patterns & OO Design...