Balakumar S
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?
By Balakumar S in .NET on Jan 17 2018
  • Charu
    Nov, 2018 28

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

    • 3
  • Mohd Ahmad
    Jan, 2019 21

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

    • 2
  • Pravin Pravin
    Feb, 2018 6

    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.

    • 2
  • Vijay Saxena
    Jan, 2020 10

    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

    • 0

Most Popular Job Functions


MOST LIKED QUESTIONS