views:

59

answers:

1

I have this scenario in most of the WindowsForms having grids I have a sequence of code which is similar - AddNewRow(in grid),CreateNewEntity,notifyUser,few other steps Now, I want to use a template kind of pattern.But,my issue is with CreateEntity method since sometimes it is passed a parameter which is different depending on the type of object being created.Should I make createentity accept an "object" type,and cast when the parameter is to be used.What other way can I tackle this design issue? Also,CreateEntity returns the object being created.

Actually, my scenario has MVP pattern.Now,most of the interaction between presenter and view in most forms is the same - user clicks add,a new row is added with some default values for the entity(to show in the grid),n some other common stuff

A: 

Have you considered using a templated function? This probably isn't a good example, but it's hard to imagine what a good example would be without more specific information:

interface IInitializable
{
   void Initialize(string input);
}

public T CreateNewEntity<T>(T inputObject, string otherData) where T : IInitializable
{
   inputObject.Initialize(otherData);
   return inputObject;
}
BlueMonkMN
this might be the solution.will try it out.Actually, my scenario has MVP pattern.Now,most of the interaction between presenterand view in most forms is same - user clicks add,a new row is added with some default values for the entity(to show in the grid),n some other common stuff.
jess