开发者

Looking for design help

开发者 https://www.devze.com 2022-12-27 16:42 出处:网络
I have this scenario in most of the WindowsForms having grids I have a sequence of code which is similar -

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 sometim开发者_C百科es 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


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号