samedi 11 décembre 2021

Design pattern that can take either obj-X or obj-Y and turns either of those into obj-Z C#

I've been sitting with this for quite some time, trying to figure out which design pattern to use, or whether it even fits into any of the design patterns. I have 3 objects. Object X Object Y Object Z Object X and Object Y have some similarities in them. I have the need to transform these, 1 at a time into another object, being Object Z. But i can't figure out which way is best to do this. I have to use a design pattern to do this. I've looked into factory, abstract factory, prototype and builder. While all of these seems to be able to work, it just seems really forced. Hopefully it makes sense what i'm trying to do.. Does anyone now an approach to to it ?

To simplify it with pseudo code it's something like this

new ObjectX(Customer) { name = "bob", age = 22, spent = 3200, vip = false}

new ObjectY(Employee) { name = Frigg, age = 24, jobTitle = developer, monthlyPay = 4000}


new ObjectZ(people) { name = ObjectX.name, age = ObjectX.age}
new ObjectZ(people) { name = ObjectY.name, age = ObjectY.age}

Aucun commentaire:

Enregistrer un commentaire