By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,892 Members | 1,238 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,892 IT Pros & Developers. It's quick & easy.

Static class vs provider class

P: n/a
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 ***
Jun 27 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Jun 27, 11:25*am, Mike P <mike.p...@gmail.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
Jun 27 '08 #2

P: n/a
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<CategoryDetailsGetCategories()
{
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;
}
...
}

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #3

P: n/a
On Jun 27, 12:03*pm, Mike P <mike.p...@gmail.comwrote:
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
Jun 27 '08 #4

P: n/a
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
Jun 29 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.