vendredi 17 juillet 2020

Application Design, How to call methods on far away classes without creating a mess?

I have a graphic example so you understand what I mean:

MasterClass wants to use class A, B and C, but B is inside A, and C is inside B. So the two ways that I know how to solve this problem are these:

1.Class B will have methods that will call directly into Class C methods, and class A will have methods that will call B methods (including C Methods) as the image: Example1

2.On Solution two every class has a getter what will return the class that they are usign so the other classes can call their methods directly, I mean, if MasterClass wants to use methods on C, it will call method getClassB() from Class A and then call the method getClassC(): enter image description here

Sadly I end up always on situations like this, so I dont know if it is a very commun situation when designing or it is just that i dont know how to design. In the last case, I will be gratefull if you can recommend me material so I can learn How to create clean and modular programs since a lot of my programms end up with a lot of classes interconecting.

Aucun commentaire:

Enregistrer un commentaire