jeudi 5 mai 2016

What pattern to use in this case (interface implementation)

I have a dataset that can be created by a few ways, one of them is by parsing some text, the other way is from a CSV format, the third way is by importing it from a database.

Currently, this is the interface:

 public interface IMyDataMaker
 {
       public MyDataSet MakeData();
 }

and this is the text parser class:

 public class MyDataSetTextParser : IMyDataMaker
 {
       private readonly string textToParse;
       public MyDataSetTextParser(string text)
       {
            textToParse = text;
       }

       public MyDataSet MakeDate()
       {
            // parse the text and return the dataset
       }
 }

the csv parser is closer to the text parser, this is the database class:

 public class DbMyDataSetMaker : IMyDataMaker
 {
       private readonly SqlConnection connection;
       public DbMyDataSetMaker(SqlConnection sqlConn)
       {
            connection = sqlConn;
       }

       public MyDataSet MakeDate()
       {
            // connect to the db and make the dataset
       }
 }

Is this the correct pattern to use in this case?

Aucun commentaire:

Enregistrer un commentaire