Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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.

Anybody looking for a graduate programmer (Midlands, England)?
  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...