This content has been marked as final.
Show 1 reply
-
1. Re: Managing access to hierarchies
jamesstrachan Oct 6, 2004 11:18 AM (in response to villo)Villo,
A cursory look at OJB suggests that it should successfully load and store objects of the different classes.
My approach to this problem would be to create an abstract super class above all the actual user classes.
so you have a hierarchy :-public abstract class AbstractUser { ... } public class InternalUser extends AbstractUser { ... } public class Customer extends AbstractUser { ... }
You can then have a single getter method and setter method using the abstract class as follows :-public AbstractUser getAbstractUserValueObject( String username ) { ... }
and test for what you have received on return either with instanceof :-AbstractUser aUser = remote.getAbstractUserValueObject( String username ); if ( aUser instanceof Customer ) { ... }
or by having an abstract methodpublic String getUserType()
in the abstract class which is implemented to return a different code for each concrete class.
It would be a good idea to have a set of finder methods that return only instances of each concrete class.
I would also be a bit worried that you may get clashes of usernames between the various sets of users. You may avoid this if you have a fairly small user population and can prevent reuse of the same name.
I have an example of this approach. It's too large to post here but I could zip it up and e-mail it to you.
James