Where does the responsibility lie ?

Posted by jmls on 22-Feb-2011 12:43

I have

1) A user class that represents the current state of a particular user

2) A session singleton that had instantiated this user class to represent the logged on user

3) An Activity class that logs user activity

I am not concerned about data layers etc right now, but what is interesting me is the following scenario

At the moment, the call to log user activity is in the user class. That is, when the user state changes, the user class is responsible for notifying the activity class about the change.

I feel that it would be better if the user class were to have an event defined (StatusChange) that the activity class subscribes to. So, when the user status changes, it is published, and the activity class is notified of the change.

This is all well and good for the above scenario (1,2 and 3). However, there are some circumstances where a session needs to change the status of a user that is not logged on, or is not the current session user. In this case, the activity instance would know nothing about the "other" user  class and would therefore miss the event.

So, what are the solutions ?

1) Keep with the existing structure (user instance has to call a method in the activity class)

2) Move to events in the user class (how to notify the activity class)

3) Move the event to the session, so that the activity class would be able to pick up *all* status changes of *any* user object

4) Something I haven't thought of (this is the most likely option!)

All Replies

This thread is closed