Suppose I have a class clubMember
and a class user
. Only club members can be users, users have login data additional to other club member vars, and club members’ characteristics influence what rights as users they have, so user
extends clubMember
.
Now suppose a club member wants to use the grails servlet I am currently programming. Creating a new user
instance would lead to a double entry, plus I would lose all the links existing between the previous member and other classes. So perhaps converting the type of the clubMember
to user
would be the best way to proceed? If so, how could that be done (in Groovy)?
Or, could you recommend me an implemention method other than subclasses? Ideally, requests such as “list all members” should also return users, is this even the case with subclasses? (Edit: It is the case in my grails app)
Related: Java: Creating a subclass object from a parent object, Is it ever valid to convert an object from a base class to a subclass