Collection of objects with common Abstract base class

前端 未结 1 1614
予麋鹿
予麋鹿 2021-01-28 17:04

I have an abstract class called generic, implemented as follows:

public abstract class generic
{
    public string creatorID { get; set; }
    public string item         


        
相关标签:
1条回答
  • 2021-01-28 17:23

    To me, this looks like a class factory.

    You need a method that takes a DataRow, looks at its fields, and decides which subclass of generic should be created for that row. Then it creates the appropriate object newObj, calls newObj.setParameters(dr), and returns newObj.

    Preferably, the actual factory method doesn't take a DataRow, but rather just the one scalar value (int, string, whatever) that indicates the type to be created.

    Perhaps the class factory is passed in by dependency injection; you could go simple or elaborate on this.

    0 讨论(0)
提交回复
热议问题