mardi 17 novembre 2020

How to join 2 unrelated classes into a single type without using inheretence

I have 2 classes: X and Y. None of them is related or have same properties. But there's another class Z that have setters and getters where the setter could accept of type X or Y and getter could return of type X or Y. I thought of having a parent class Parent for x,y and use it as a type for setters and getters .. but I don't think it's a good design and will break the whole meaning of inheretence. What can I do in such case? Other than using generic type 'T' for z class

Aucun commentaire:

Enregistrer un commentaire