I am creating a C# console app for reading pipe-delimited text files and import into database. I get a list (a text file) of suppliers, from which the organization buys office accessories along with the accessories they supplied (Drawers to Pins, you name it). The list contains both Organizations and individuals that meet these demands. The text file has FirstName, LastName, MiddleName columns. For individual suppliers' data, this is good. But if its an organization, then only the LastName column has the data, with the organization name. Other than this there is one more column called supplierType that helps me differentiate the individual supplier and organization (SupplierType 1 means individual, 2 means organization)
Now I created a Person and Organization classes to be used in the supplier class.
class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string? MiddleName { get; set; }
//public string FullName { get; }
}
class Organization
{
public string OrganizationName { get; set; }
}
In the supplier class I want to use these classes interchangeably based on the supplierType.(like the strategy pattern) Since the properties are different in person and Organization class I am not clear how to accomplish this
class Supplier()
{
int SupplierType
//Something like the below.
ISupplier supplier;
List<Product> Products;
}
Void Main()
{
Read a line from the text file
Supplier purchases = new Supplier()
purchases.SupplierType = Get the supplierType from the line.
purchases.supplier = if SupplierType is 1 then assign person class, if 2 assign Organization class
//How to accomplish the above when the properties are changing between person and Organization class
}
I dont know whether this is a good design or probably there is a better way. Please help