4
Reply

I have scenario that to use different data source at run time hence i just created common interface used Factory Pattern. But my challenge is, each datasource expect different parameters Lets say i have GteData() in the interface, For 1 st datasource, i would pass as GetData(int i) but for the second datasource it would be GetData(int i, string s) Having this, still factory pattern would be preferable or any other alternate solution?

Balakumar S

Balakumar S

7y
6.6k
3
Reply

    we can have optional parameters in the getdata definition and use it as needed.

    Please use provider pattern and in your GetData method prepare a class and pass that class object rather than passing multiple parameters.

    Create a base parameter class; use it in your GetData method as parameter. and in your method call, just pass the actual implementation of parameter base class. Hope that solves your issue.

    use composite design pattern .. create datasource base class(abstract) and inehrit diff concrete data source with all having own logic to getdata method with diff params. now in main class will keep reference of base object and initialize this at runtime and which intern will invoke appropriate concrete method