Basically I have an entity (called Session) which will provide many different Services. Each service can be selectively turned ON or OFF by the user (signin or signout). I am not sure what’s the best design to represent this. See UML
From a programming use case perspective, the interactions with a Session instance:
Session session = new Session( '1234' ); // 1234 is the userid session.start(); session.serviceSignIn( ServiceType.DELICIOUS ); .... do stuff ... session.serviceSignOut( ServiceType.DELICIOUS ); session.serviceSignIn( ServiceType.MAGNOLIA ); .... do stuff ... session.serviceSignOut( ServiceType.MAGNOLIA );
Another possible design:
session.delicious().signIn(); .... do stuff ... session.delicious().signOut(); session.magnolia().signIn(); .... do stuff ... session.magnolia().signOut();
Which should I prefer ? What mistakes am I making ?
Why explicitly name the services? Presumably this is going to be hooked up to some GUI or other interface correct? Probably enough to refer to them by strings like ‘delicious’. Also why not make each service a class that can sign it self in and out?
You should also make the Service interface have operations for doing things with the service such as adding bookmarks.