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 ?

  • Why don't you use a Drawer-object that knows how to draw a Battery object (or a whole car) ? You have then decoupled the battery-business-object from the drawing functionality.
    – valenterry
    Feb 21, 2015 at 20:12
  • I am not sure if this is going to work.Because objects are going to be interactive etc. So it isnt just drawing. Also I want extendability.
    – GorillaApe
    Feb 21, 2015 at 20:44
  • You will need one class for each interaction. you also can extend the battery class, unless you want different batteries to be drawn different. If that is the case, the only way to decouple presentation logic from the batteries is using an object algebra - see 'expression Problem' for more information.
    – valenterry
    Feb 21, 2015 at 21:15

1 Answer 1


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."

public float AmpHours { get; set; }
  • yes it is part of electrical system.however electrical system classes have little to do with drawing.So here is the problem in a system the way objects are referenced are different than in the canvas that should contain just drawable objects
    – GorillaApe
    Feb 22, 2015 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.