I need to have possibility of comparison of Product, AdvancedProduct (and other classes that inherit from class Product) How it is better to realize hierarchical check of fields? For example, i want to check two AdvancedProduct classes, first i check fields the basic class Product then check additional fields of AdvancedProduct and return in some form (???) changes between them (maybe class PChanges???). Whether there is a suitable template? How make all this, but to make rather flexibly for the subsequent use?
public class Product
{
public string ID;
public string Name;
public Product(string id, string name)
{
this.ID = id;
this.Name = name;
}
}
public class AdvancedProduct : Product
{
public string CurrentVersion;
public AdvancedProduct(string id, string name, string version)
: base(id, name) { }
}
public class PChanges
{
public bool NameChanged = false;
public bool VersionChanged = false;
public PChanges() { }
}
public class ProductComparer
{
PChanges changes = new PChanges();
public ProductComparer() { }
public PChanges Compare(AdvancedProduct p1, AdvancedProduct p2)
{
if (p1.Name != p2.Name)
changes.NameChanged = true;
if (p1.CurrentVersion != p2.CurrentVersion)
changes.VersionChanged = true;
return changes;
}
}