Its not simply that your object model is not correct but that things are just not modeled the way you have approached it. Generally when you create an object it does not change its class. Ever. What you are trying to do is have a object of a class that "can be" another class another time by making it so within the application and can be another class later on etc etc. Many run into this at one time or the other and it has been solved by using role classes. i.e. your person class does not change but instead takes on roles. One of the roles is employee. You can also have a role of administrator which the person can also take on or if an administrator must first be an employee then administrator can be a role (taken on/added to) an employee and not person. This pattern is called the role-object/actor- role/actor-participant pattern which you can read up on to get a better understanding. You can also look at the state pattern which is also quite similar.
Next you will have to implement this model by either creating separate classes if their behaviour is significantly different or You can have a flag or enum in the person or employee class to indicate if the person is now playing an employee or administrator role if they classes are structurally the same but you just want it to do something else in the case of it being in either one of these roles, like permissions. Just lookup the patterns I referred above and you'll understand it more. Jide On Sep 16, 11:22 pm, Matt Mangold <[email protected]> wrote: > In my application, I have an object hierarchy of Person->Employee- > > >Administrator. > > I want to be able to take an existing employee and make them an > administrator. > > I know that in OO world, this is not possible, you must first destroy > the employee object create a new Administrator object and build out > the Administrator's properties to match the employee. > > I really don't want to go through all that work. I much rather just > update the discriminator value for the employee in the database to an > administrator discriminator value. > > What are my options here? I know that the right way to do it is to > delete the employee and create a new admin, but that is a lot of work > and is error prone due to all of the properties of the employee. > > This seems like a common scenario. What is the best way to handle > this? -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
