I have a metamodel that builds like this:
class ModelElement
{
string id;
}
class Package : ModelElement
{
List<Package> nestedPackages;
List<Class> ownedClasses;
}
class Class : ModelElement
{
}
Now I have created two Models, and I want to check if they are identical. I would like to compare the element IDs, and I do not want to write a method for any type of element.
Package a;
Package b;
compare(a.nestedPackages, b.nestedPackages);
compare(a.ownedClasses; b.OwnedClasses);
Since the class and package both inherit from ModelElement, both have identifiers. So I want to write a compare function that compares identifiers. I was thinking about using Generics, but the generic data type does not have an id attribute. Any ideas?
source
share