dimanche 9 mai 2021

Which is the right design pattern?

I need some advice on which design pattern to use for the problem at hand.

I want to write a library allowing to retrieve external-data from some source (a local file, from the web, ...) and make this data accessible via an interface. The datasets are diverse and possibly change on case-by-case basis (e.g. population counts, weather-data, ...).

So extensibility and easy-maintenance is important.

I am thinking to use the Bridge pattern here. Is it a good choice? Haven't written code yet, just figuring out the best design.

Any help is much appreciated! Cheers /S

class DataSource 
{
protected:
   DataSrcImpl* _impl;

public:
   DataSource(DataSrcImpl* arg) : _impl(arg) {};

   virtual void retrieveData() = 0;
}

class PopulationDataSource : public DataSource
{
private:
   // members to store data

public:
   PopulationDataSource(DataSrcImpl* arg) : DataSource(arg) { };

   virtual double getDataA () const = 0;
   virtual std::string getDataB () const = 0;
   ...
}

class WeatherDataSource : public DataSource
{
private:
   // members to store data

public:
   WeatherDataSource(DataSrcImpl* arg) : DataSource(arg) { };

   virtual double getDataC () const = 0;
   virtual std::string getDataD () const = 0;
   ...
}

Aucun commentaire:

Enregistrer un commentaire