0

I have a configuration class that is shared in my project:

public class BarcodeConfig
{
    public string LotStandardDigits { get; set; }
    public string LotOldStandardDigits { get; set; }
    public int LotOldNumofDigits { get; set; }
    public int LotStandardNumofDigits { get; set; }
}

In my main class implementation i have 2 classes. One static (for utilities and the other that contains all my intended logic:

public static class BarcodeUtil
{
...
}

public class BarcodeBLL
{
...        
}

I want to be able to use the same configuration class for both my static and normal class. Is it best to make the config class static? or not?

Steve
  • 203,265
  • 19
  • 210
  • 265
e4rthdog
  • 4,841
  • 4
  • 31
  • 79

2 Answers2

4

I prefer instantiating config object. In case of those static methods I'd pass the config as an argument to each of this utlility methods separately.

This allows to use utility methods for completely different purposes by completely different modules at the same time and makes them more elastic.

Grzegorz Sławecki
  • 1,587
  • 13
  • 26
0

If you use unit tests it's better not to have static classes, because it's much harder to fake them. This is an interesting discussing:

When to use static vs instantiated classes

Community
  • 1
  • 1
Rui Jarimba
  • 9,732
  • 10
  • 46
  • 74