This is how I would do this:
1. Create a base interface for all the information is required to create
a user. (IUserCreationRequest)
2. Create extension interfaces for other criteria that can be used to create
a user. (IAddress2Source, ITitleSource)
3. Create one method/service that takes in the base request and returns a
reference to the user.
4. Have every aspect create its own value object that implements at least
the base interface and also any other interfaces for data it can provide:
e.g:
public class CreateGuestUser : IUserCreationRequest ...
public class CreateInternalUser : IUserCreationRequest, IAddress2Source,
ITitleSource
5. Have the method/service create the basic user object and then populate
any extra data on it based on the interfaces the incoming request implements.
public IUser CreateUser(IUserCreationRequest userRequest)
{
IUser user = CreateUser(userRequest);
if (userRequest is IAddress2Source)
ApplyAddress2Data(user);
if (userRequest is ITitleSource)
ApplyTitleData(user);
...
return user;
}
The implementation for CreateUser can be made more dynamic but I think you
get the idea.
Good luck!
--
Saad Rehmani / Prodika / Dallas / TX / USA
I have several pages that will contain forms used for registering with
our website. These form won't always show the same information, as
their primary purposes are different, but part of the processing will
be the registration.
I'd like to have just one method for the entire site that handles the
creation of new account, referenced by all these forms.
So, assuming that form 'a' contains 8 fields required for
registration, form 'b' contains the min of 4, form 'c' contains 7 and
form 'd' has all 11, how would you create the method and then use it?
I'm new to C#, so bear with me. I've heard of overloading, but I think
I'd basically need 4 copies of the same method, which seems somewhat
over the top. I wondered about putting the form fields into an object
of some kind and then passing that object to the registration method.
Would that work?
What do you think would be the best way to get varying ammount of data
into a single method? Any examples and/or tutorial sites would be
greatly appreciated.
Thanks
Kevin