I am looking for a way to design my application. Suppose you had a car drawing thing. Car has multiple parts.Some are going to be visible some are not.For example battery should be drawn. So someone would create a class Battery. Some other data such as warranty tests passed etc arent going to be drawn. My problem is that I want to separate technical data from object to be drawn. For example battery has tons of technical specs (capacity,low/max temperature etc).
So for example I read the data from a file that has all the data both technical and other such as color etc and transform these data into Objects.
Then I want to add them to a canvas in order to be drawn. However not all objects need to be drawn.Problem here is that for example I dont want to put canvas specific components like renderer into class like Battery.
Only solution I can think of is to create another class for each drawable like BatteryObject.However that means that another object should be instantiated and deleting etc is going to be a pain. Is there any other approach ?
3
The answer to your question is going to depend greatly on the degree that your “data” needs to be “intelligent.”
For example, if you merely wanted to display the specifications on the screen, you could simply provide the data as a collection of attributes without type. For example:
var attributes = new list<KeyValuePair<string, string>>();
If, on the other hand, your battery is part of an electrical system that you might want to analyze later, your data would not only have to be actual numeric values, but you would also need to know units, since current is treated differently from voltage and the gauge of wires takes on some relevance, etc.
Some attributes have constraints. Lead-acid batteries are different from lithium ion batteries (though they are both batteries), but there are only a limited number of battery types, so you might want to constrain input to a known list of types. Last time I checked, you couldn’t put a Zero-Point Module in a car.
If you still want to represent your specifications as first-class object properties in your battery class, C# allow you to decorate those properties with a custom Attribute that will allow you to identify them as “product specifications.”
[Specification]
public float AmpHours { get; set; }
1