There is a design pattern that I can apply to this kind of scenario?
I have processes classes that implements BaseProcess class: BaseProcess has a CreateProcess(BaseObject o) method and BaseObject has two childs or many.
ProcessClassA : BaseProcess
ProcessClassB : BaseProcess
ObjectA : BaseObject
ObjectB : BaseObject
I want to be able to have a class Process that can have multiples ProcessClasses like in this case 2 classes but that can have more in the future like 3 classes or more and that process. And I want to use the class like this:
Process.Process(BaseObject o) and send specific object and let the Process class call the specific class such as ProcessClassA if I send ObjectA. The problems is I dont want to use if inside process becuse I will need to one that class when I add ProcessClassC
Example:
ObjectA exampleObj = new ObjectA
Process p = new Process(List<BaseProcess>{ProcessClassA ,ProcessClassB }) //Something like this but dont need to be in the contructor or be a list could be //something else but that allows not to violate Open Close principle.
p.Process(exampleObj) => ProcessClassA.Process(exampleObj)
Aucun commentaire:
Enregistrer un commentaire