Static class vs provider class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike P

    Static class vs provider class

    What is the difference between a helper class and a provider class? I
    have seen plenty of helper classes as static classes with only static
    methods, but I have also recently seen a provider class that is also a
    static class with static methods. What should be the difference between
    them?



    *** Sent via Developersdex http://www.developersdex.com ***
  • Jon Skeet [C# MVP]

    #2
    Re: Static class vs provider class

    On Jun 27, 11:25 am, Mike P <mike.p...@gmai l.comwrote:
    What is the difference between a helper class and a provider class?  I
    have seen plenty of helper classes as static classes with only static
    methods, but I have also recently seen a provider class that is also a
    static class with static methods.  What should be the difference between
    them?
    Well, I haven't heard "provider class" used much as a term, but I'm
    guess it acts as a static factory. In other words, it doesn't provide
    any functionality other than giving an appropriate implementation of a
    particular interface/abstract class which in turn *does* provide the
    functionality.

    What's your context?

    Jon

    Comment

    • Mike P

      #3
      Re: Static class vs provider class

      Here are a couple of cut down examples of classes I have seen labelled
      as 'provider' classes :

      1)

      public class SqlArticlesProv ider : ArticlesProvide r
      {
      /// <summary>
      /// Returns a collection with all the categories
      /// </summary>
      public override List<CategoryDe tailsGetCategor ies()
      {
      using (SqlConnection cn = new
      SqlConnection(t his.ConnectionS tring))
      {
      SqlCommand cmd = new
      SqlCommand("tbh _Articles_GetCa tegories", cn);
      cmd.CommandType = CommandType.Sto redProcedure;
      cn.Open();
      return GetCategoryColl ectionFromReade r(ExecuteReader (cmd));
      }
      }
      ....
      }

      2)

      public static class CleanseJobProvi der
      {

      /// <summary>
      /// Returns an XmlDocument
      /// </summary>
      /// <param name="userName" ></param>
      /// <param name="password" ></param>
      /// <param name="jobID"></param>
      /// <param name="userID"></param>
      /// <returns></returns>
      public static XmlDocument GetDefaultExtra ction(string userName,
      string password, int jobID, int userID)
      {
      slndat13.Integr ator intergratorProx y = GetProxy(userNa me,
      password);
      object[] iresult =
      intergratorProx y.DefaultEmptyE xtraction(jobID , userID);
      XmlDocument doc = new XmlDocument();
      if (iresult[0] is DataSet)
      {
      if (((DataSet)ires ult[0]).Tables.Count 0)
      {
      DataRow dr =
      ((DataSet)iresu lt[0]).Tables[0].Rows[0];
      SqlXml sqlx = (SqlXml)dr[0];
      if (!sqlx.IsNull)
      {

      //System.Diagnost ics.Debug.Write Line(sqlx.Value );
      doc.LoadXml("<j ob>" + sqlx.Value + "</job>");
      }
      }
      }
      return doc;
      }
      ...
      }



      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Static class vs provider class

        On Jun 27, 12:03 pm, Mike P <mike.p...@gmai l.comwrote:
        Here are a couple of cut down examples of classes I have seen labelled
        as 'provider' classes :
        >
        1)
        >
        public class SqlArticlesProv ider : ArticlesProvide r
        Okay, so that's a normal kind of class, overriding a method.
        public static class CleanseJobProvi der
        Hmm. That's not terribly clear, and I'd argue that it would make for
        more testable code if it implemented an interface instead of being
        static. That would allow dependency injection in the normal way.

        Jon

        Comment

        • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

          #5
          Re: Static class vs provider class

          Mike P wrote:
          What is the difference between a helper class and a provider class? I
          have seen plenty of helper classes as static classes with only static
          methods, but I have also recently seen a provider class that is also a
          static class with static methods. What should be the difference between
          them?
          To me a provider class is a class that provides an implementation
          of a specific API (for those that also code in Java: think SPI).
          Completely different from a helper class and never static.

          Arne

          Comment

          Working...