fguihen Posted May 4, 2006 Posted May 4, 2006 doing a little project. im demonstrating inheritance. i have an employee class. classes which inherit this are BusinessEmp, MaintenanceEmp, ITEmp....... i have a form to create employees. a dropdown box lets me select the employee type. rather than hardcoding it if(combo.selectedItem = "businessEmp") { //create new businessEmp } if(combo.selectedItem = "ITEmp"() { //create new ITEmp } ... ... i want it to be extensible, so that if someone added a different type of employee, all they would have to do is add in the new employee class. is this possible ( cant use a database)?i can hard code them if i want, but id rather learn to do it this way, seems like there would be more merrit to it Quote
Cags Posted May 4, 2006 Posted May 4, 2006 The way I would do it is rather than inheriting from a base class use an Interface, then you create each employee type as a plugin (theres an excellent plugin example in the tutors corner). You could probably still do the plugin approach using a base class, but as i've never attempted this and as such I couldn't say much more. The basic idea is that a plugin controller will load a list of each available employee type. You can then use the SelectedIndex value of the combobox to create an object of that type. Quote Anybody looking for a graduate programmer (Midlands, England)?
Administrators PlausiblyDamp Posted May 4, 2006 Administrators Posted May 4, 2006 If I can dig it up I do have a sample knocking around somewhere (a continuation of the tutorials I will get round to finishing in the tutor's corner). It's a VB sample that dynamically loads a list of available plugins that the UI can use to display to the user and a factory that then creates the correct instance internally. Not too difficult to do either, getting the plugins designed correctly is the biggest challenge. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
fguihen Posted May 5, 2006 Author Posted May 5, 2006 yea, that sample would be great. thanks for the responses guys Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.