Background:
I am trying to write an application in C#.
Requirement: We are required to receive a request from client application, handle it and return a collection of Components. Component in our system is a complex class: and with 15/20 optional properties e.g. Boolean? IsAvailable, String Name, double? Price etc
The collection of components can at most have two Component instances which users refer to as: RightComponent of type Component LeftComponent of type Component
Current Set up: We have a builder class that builds Component instance with the required properties eg IsAvailable is only set to true if request wants information on component availability.
we take a client request, pass it to RequestHandler class that reads the propeties of the request object, then it uses Componentbuilder to build right and left components.
I ceated a class ComponentAggregate that has two properties: RightComponent and LeftComponent
Then in my RequestHandler class, when I call HandleRequest, I have a method that reads propeties, using if then else statements, builds 2 Component objects from ComponentBuilder and returns ComponentAggregate back.
This code is getting messy because RequestHandler has so many if then else statements plus the Componentbuilders are passed around until Component is created completely. This means RequestHandler's private methods return ComponentBuilder type.
Can you recommend me a better approach in designing this application?
This is a hypothetical example to understand which pattern you recommend to solve this problem. I have omitted writing code in the question so we can concentrate on the pattern that we need.
Many thanks
Aucun commentaire:
Enregistrer un commentaire