Static class vs provider class

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

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?
 
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
 
Here are a couple of cut down examples of classes I have seen labelled
as 'provider' classes :

1)

public class SqlArticlesProvider : ArticlesProvider
{
/// <summary>
/// Returns a collection with all the categories
/// </summary>
public override List<CategoryDetails> GetCategories()
{
using (SqlConnection cn = new
SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new
SqlCommand("tbh_Articles_GetCategories", cn);
cmd.CommandType = CommandType.StoredProcedure;
cn.Open();
return GetCategoryCollectionFromReader(ExecuteReader(cmd));
}
}
....
}

2)

public static class CleanseJobProvider
{

/// <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 GetDefaultExtraction(string userName,
string password, int jobID, int userID)
{
slndat13.Integrator intergratorProxy = GetProxy(userName,
password);
object[] iresult =
intergratorProxy.DefaultEmptyExtraction(jobID, userID);
XmlDocument doc = new XmlDocument();
if (iresult[0] is DataSet)
{
if (((DataSet)iresult[0]).Tables.Count > 0)
{
DataRow dr =
((DataSet)iresult[0]).Tables[0].Rows[0];
SqlXml sqlx = (SqlXml)dr[0];
if (!sqlx.IsNull)
{

//System.Diagnostics.Debug.WriteLine(sqlx.Value);
doc.LoadXml("<job>" + sqlx.Value + "</job>");
}
}
}
return doc;
}
...
}
 
Here are a couple of cut down examples of classes I have seen labelled
as 'provider' classes :

1)

public class SqlArticlesProvider : ArticlesProvider

Okay, so that's a normal kind of class, overriding a method.
public static class CleanseJobProvider

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
 
Mike said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top