I have a use case to draw some machine in a CAO software that the user can configure (for example setting the length, if an option has to appear graphically or not, etc.). This is done through the software (Autocad) using dynamic properties, layers or block to show/hide, so with different type of behaviours. The number of possible options vary from one equipment to another, and we often had new parameters to our products.
I started to use the decorator pattern to manage the different parameter of the equipment. My main concern now is that some parameter values are interdependant (I need for example the current value of the current decorator multiplied by the value of another one... that may be wrapped into the first decorator, or that may wrap it).
Do you have any clue if : - What I want to achieve is feasible in the boundaries of the decorator pattern ? - I am totally wrong and should use a different kind of design pattern for my use case ?
Here is some simplified material of my implementation :
My component interface
public interface Component
{
void Draw();
void Store();
}
I have a "machine" class that represent the basic information of the machine that is fixed :
public class Machine : Component
{
public int MachineID { get; set; }
public void Draw()
{
//Do some stuff
}
public void Store()
{
//Do some stuff
}
}
An abstract class that represents the parameters:
public abstract class Parameter : Component
{
internal string ParameterName;
internal string Value;
internal Component BaseComponent;
public Parameter(string _parameterName, string _value, Component _component)
{
ParameterName = _parameterName;
Value = _value;
BaseComponent = _component;
}
public abstract void Draw();
public void Store()
{
//Do store data in the drawing (same procedure for any parameter)
}
}
And a concrete parameter class :
public class ConcreteParameter : Parameter
{
internal string SomeAdditionalMember;
public ConcreteParameter(string _parameterName, string _value, Component _component) : base(_parameterName, _value, _component) { }
public override void Draw()
{
this.BaseComponent.Draw();
//Draw in a specific way in addition to parent drawing
}
}
Thanks in advance for any advise on the topic !
Aucun commentaire:
Enregistrer un commentaire