Answer the question
In order to leave comments, you need to log in
How to bring methods with different parameters to a single interface?
There are two generator classes, for example URLs. I want to make sure that they implement a single interface and the calling code doesn't care what generator it works with - it calls the method, gets the URL.
The problem is this: for the same method, one class needs a little more data than another. How to resolve this situation?
Making an excessive number of parameters in the function signature and then ignoring them where they are not needed is somehow not very good. The adapter pattern is also not suitable here, because the data must come from outside, and the adapter will have to receive it somewhere on its own. If you create some kind of abstract parameters object (or an array), then encapsulation is violated in the calling code - you need to know what exactly we are collecting the object for.
Are there any other options, or have I already listed everything? :)
Answer the question
In order to leave comments, you need to log in
Did I understand correctly:
you have class A, which contains N parameters.
there is a Construct_1 class that does something based on M parameters, where M is a subset of N
there is a Construct_2 class that does something similar to Construct_1 actions based on M` parameters, where M` is a subset of N.
You want C_1 and C_2 were united by one interface. Those. someone from the outside creates C_1 or C_2 depending on the conditions, passes it, for example, to A, and A calls the general method, giving the necessary data there, but not knowing what is in front of it - Construct_1 or Construct_2?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question