Discussion:
Instance vs Static + Option
Brady Kelly
2008-05-07 12:39:36 UTC
Permalink
I am busy with a new ConfigHelper class, and can't seem to decide on which
approach to take. The class is responsible for adjusting the config table
in two databases, control and test. My dilemma is whether I make
ConfigHelper a static class, and tell it which database to access for each
task, or use instance methods and have one instance for each database.


===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Davy J
2008-05-09 10:06:38 UTC
Permalink
I've been using a proxy pattern for stuff like this, I tried using
Spring.Net to do it, but what a nightmare to configure for just one or
two objects.
here's a quick and dirty example
hth. Davy J


public interface ISettings
{
object ReadValue(string name);
void WriteValue(string name, object value);

}

/// <summary>
/// Public class that is used to read the settings from, not there
is no real implementation in this class
/// it serves as a proxy class.
/// </summary>
public class Settings : ISettings
{
private ISettings proxy;
#region ISettings Members

private void CheckProxy()
{
if (proxy == null)
{
switch (Properties.Settings.Default.CodeVersion)
{
case "DEBUG":
this.proxy = new TestSettings();
return;
default:
this.proxy = new LiveSettings();
return;
}

}
}
public object ReadValue(string name)
{
CheckProxy();
return proxy.ReadValue(name);
}

public void WriteValue(string name, object value)
{
CheckProxy();
proxy.WriteValue(name,object);
}

#endregion
}

/// <summary>
/// Application class.
/// </summary>
public class DemoClass
{
//We create a new class and don't worry about what we will be attacking.
private Settings settings = new Settings();
private string connectionString = string.Empty;
public DemoClass()
{
//We get a connection string from the class.
connectionString = (string)settings.ReadValue("ConnectionString");
}
}

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Peter Obiefuna
2008-05-09 14:44:03 UTC
Permalink
I would write one static helper class and pass the control/test value as a
parameter.


public static string SayHello(string message, Environment environment){
if (environment == Environment.Control){
return string.Format("Hello {0} from Control", message);
}
return string.Format("Hello {0} from Test", message);
}

--------------------------------------------------
From: "Brady Kelly" <***@CHASESOFTWARE.CO.ZA>
Sent: Wednesday, May 07, 2008 6:39 AM
To: <DOTNET-***@DISCUSS.DEVELOP.COM>
Subject: [DOTNET-CLR] Instance vs Static + Option
Post by Brady Kelly
I am busy with a new ConfigHelper class, and can't seem to decide on which
approach to take. The class is responsible for adjusting the config table
in two databases, control and test. My dilemma is whether I make
ConfigHelper a static class, and tell it which database to access for each
task, or use instance methods and have one instance for each database.
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Nick Robinson
2008-05-16 19:38:14 UTC
Permalink
There isnt enough context to go off, but I would personally prefer an instance over statics. I have found that as soon as I even hint at the word "helper" it polarizes my subsequent thoughts on how to design something. Rarely in my experience do I see a helper without statics (a recent project was more helper than anything else), so as soon as I use the term, I immediately think it will probably have statics.

Nick.
-----Original Message-----
Sent: Wed, 7 May 2008 14:39:36 +0200
Subject: [DOTNET-CLR] Instance vs Static + Option
I am busy with a new ConfigHelper class, and can't seem to decide on which
approach to take. The class is responsible for adjusting the config table
in two databases, control and test. My dilemma is whether I make
ConfigHelper a static class, and tell it which database to access for each
task, or use instance methods and have one instance for each database.
===================================
This list is hosted by DevelopMentor. http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Brady Kelly
2008-05-17 09:35:58 UTC
Permalink
Post by Nick Robinson
There isnt enough context to go off, but I would personally prefer an
instance over statics. I have found that as soon as I even hint at the
word "helper" it polarizes my subsequent thoughts on how to design
something. Rarely in my experience do I see a helper without statics
(a recent project was more helper than anything else), so as soon as I
use the term, I immediately think it will probably have statics.
Nick.
Maybe Provider would me more apt than helper then. Provider sounds more
dedicated.

===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Nick Robinson
2008-05-17 13:20:38 UTC
Permalink
You mean something like ConfigProvider? Does this class provide CRUD style behaviour onto a "config table", or does it do something very specific with a config table? I dont know whether Provider is the right term, but the fact it makes the class feel more dedicated is good. Of course, it could still be a helper, and thats ok.

Nick.
-----Original Message-----
Sent: Sat, 17 May 2008 11:35:58 +0200
Subject: Re: [DOTNET-CLR] Instance vs Static + Option
Post by Nick Robinson
There isnt enough context to go off, but I would personally prefer an
instance over statics. I have found that as soon as I even hint at the
word "helper" it polarizes my subsequent thoughts on how to design
something. Rarely in my experience do I see a helper without statics
(a recent project was more helper than anything else), so as soon as I
use the term, I immediately think it will probably have statics.
Nick.
Maybe Provider would me more apt than helper then. Provider sounds more
dedicated.
===================================
This list is hosted by DevelopMentor. http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
____________________________________________________________
Receive Notifications of Incoming Messages
Easily monitor multiple email accounts & access them with a click.
Visit http://www.inbox.com/notifier and check it out!

===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Brady Kelly
2008-05-17 13:42:43 UTC
Permalink
Post by Nick Robinson
You mean something like ConfigProvider? Does this class provide CRUD
style behaviour onto a "config table", or does it do something very
specific with a config table? I dont know whether Provider is the right
term, but the fact it makes the class feel more dedicated is good. Of
course, it could still be a helper, and thats ok.
Nick.
It provides an application layer maybe one up from CRUD, where it performs
sets of CRUD operations on a config table, and other operations, as required
for certain tasks. E.g. If I call SetAccountingPackage, it may set fields
in the config table to select that accounting package, create an export
directory for that accounting package, and set another field in the table to
point to that directory.

===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Nick Robinson
2008-05-17 19:57:33 UTC
Permalink
Right, that sounds like a lot of important behaviour, so back to the original question about Helper, that role feels like you lose an important class.
-----Original Message-----
Sent: Sat, 17 May 2008 15:42:43 +0200
Subject: Re: [DOTNET-CLR] Instance vs Static + Option
Post by Nick Robinson
You mean something like ConfigProvider? Does this class provide CRUD
style behaviour onto a "config table", or does it do something very
specific with a config table? I dont know whether Provider is the right
term, but the fact it makes the class feel more dedicated is good. Of
course, it could still be a helper, and thats ok.
Nick.
It provides an application layer maybe one up from CRUD, where it
performs
sets of CRUD operations on a config table, and other operations, as
required
for certain tasks. E.g. If I call SetAccountingPackage, it may set
fields
in the config table to select that accounting package, create an export
directory for that accounting package, and set another field in the table
to
point to that directory.
===================================
This list is hosted by DevelopMentor. http://www.develop.com
View archives and manage your subscription(s) at
http://discuss.develop.com
===================================
This list is hosted by DevelopMentor� http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Loading...