Hi all
Let's say I am creating a model to represent classes and properties. In
addition to this I need instances of classes and values for those
properties.
KEY:
[ClassName]
(AssociationEnd Name)
A classifier has many properties
[Classifier] (Classifier) 1-----* (Properties) [Property]
A classifier has many instances
[Classifier] (Classifier) 1-----* (Instances) [Instance]
An instance has many property values
[Instance] (Instance) 1----* (PropertyValues ) [PropertyValue]
A Property has many PropertyValues
[Property] (Property) 1----* (PropertyValues ) [PropertyValue]
I hope that's clear :-)
var personClassifie r = new Classifier();
var firstNameProper ty = new Property();
personClassifie r.Properties.Ad d(firstNameProp erty);
At this point I want to do something like this
var personInstance = Instance.FromCl assifier(person Classifier);
the implementation would look something like this
public static Instance FromClassifier( Classifier classifier)
{
var result = new Instance();
result.Classifi er = classifier;
foreach (var property in classifier.Prop erties)
{
var propertyValue = new PropertyValue() ;
result.Property Values.Add(prop ertyValue);
propertyValue.P roperty = property;
}
}
The above is a simple example. The fact is I have a pre-defined set of
property types. So descended from Property I might have
StringProperty, NumericProperty , BooleanProperty , etc
and a corresponding PropertyValue class for each
StringPropertyV alue, NumericProperty Value, BooleanProperty Value, etc
To achieve the creation of the correct PropertyValue descendant I added an
abstract method to Property
public abstract PropertyValue CreatePropertyV alue(Property property);
and implement in each descendant
public override PropertyValue CreatePropertyV alue(Property property)
{
var result = new BooleanProperty Value();
result.Strongly TypedReference = (BooleanPropert y)property;
return result;
}
Now onto the question :-)
To me this seems logical, but a little messy. I don't like the fact that
the Property class creates the instance of the PropertyValue. What I would
expect to write in code is something like
var property = BooleanProperty Value.FromPrope rty(booleanProp erty);
but obviously in this case I can't hard-code the class type into my foreach
loop. So it seems I am stuck with the Property being responsible for
creating the correct PropertyValue instances. Or do I have another option?
--
Pete
====
Let's say I am creating a model to represent classes and properties. In
addition to this I need instances of classes and values for those
properties.
KEY:
[ClassName]
(AssociationEnd Name)
A classifier has many properties
[Classifier] (Classifier) 1-----* (Properties) [Property]
A classifier has many instances
[Classifier] (Classifier) 1-----* (Instances) [Instance]
An instance has many property values
[Instance] (Instance) 1----* (PropertyValues ) [PropertyValue]
A Property has many PropertyValues
[Property] (Property) 1----* (PropertyValues ) [PropertyValue]
I hope that's clear :-)
var personClassifie r = new Classifier();
var firstNameProper ty = new Property();
personClassifie r.Properties.Ad d(firstNameProp erty);
At this point I want to do something like this
var personInstance = Instance.FromCl assifier(person Classifier);
the implementation would look something like this
public static Instance FromClassifier( Classifier classifier)
{
var result = new Instance();
result.Classifi er = classifier;
foreach (var property in classifier.Prop erties)
{
var propertyValue = new PropertyValue() ;
result.Property Values.Add(prop ertyValue);
propertyValue.P roperty = property;
}
}
The above is a simple example. The fact is I have a pre-defined set of
property types. So descended from Property I might have
StringProperty, NumericProperty , BooleanProperty , etc
and a corresponding PropertyValue class for each
StringPropertyV alue, NumericProperty Value, BooleanProperty Value, etc
To achieve the creation of the correct PropertyValue descendant I added an
abstract method to Property
public abstract PropertyValue CreatePropertyV alue(Property property);
and implement in each descendant
public override PropertyValue CreatePropertyV alue(Property property)
{
var result = new BooleanProperty Value();
result.Strongly TypedReference = (BooleanPropert y)property;
return result;
}
Now onto the question :-)
To me this seems logical, but a little messy. I don't like the fact that
the Property class creates the instance of the PropertyValue. What I would
expect to write in code is something like
var property = BooleanProperty Value.FromPrope rty(booleanProp erty);
but obviously in this case I can't hard-code the class type into my foreach
loop. So it seems I am stuck with the Property being responsible for
creating the correct PropertyValue instances. Or do I have another option?
--
Pete
====
Comment