Opinion on creating a general utility class Static

Some of what I read about it yesterday and today:

  • (SO) Should you avoid static classes?
  • (SO) When to use static classes in C # - Mark S. Rasmussen makes a nice comment here
  • Singleton vs Static - Good quote from here:
    These differences are extremely subtle, but they affect how stable the system will be after some years of subtle changes, new features, improvements, etc. Most developers do not like system maintenance, and I feel that the biggest reason is that the systems are not really designed to be maintained. By including the "singleton" template above, I abstracted the creation of the object and printed from my core business logic, which is crucial for long-term maintenance.
  • Singleton is considered stupid
  • (SO) A single method class is the best approach? - Once again, a quote from Mark S. Rasmussen:
    Customers requirement to instantiate classes for no reason; True utility classes that do not pose a bloating hazard are excellent cases for static methods — for example, System.Convert. If your project is one-time, with no future maintenance requirements, the overall architecture is really not very important - static or not static, it really doesn't matter - development speed, however.
  • (SO) Creating methods for all static in the class - Speed ​​is not a problem for me now, the code should work * PROPERLY * when calling several clients from the website and (possibly, but unlikely) several clients from the admin application.

() , "Common" "clsCommon". , , , .

, ( ):

  •  
  • :  
    •     
    • CopyFile     
    • DecryptAndCopyFile  
     
  • XML:  
    •     
    • GetSpecificXMLValue ( XML )     
    • SetSpecificXMLValue     
    • DeleteSpecificXMLValue  
     
  •  
  • (`return DateTime.Now.ToString( "yyyyMMddHHmmss" );`)  
  •  
  • .  
  • , ( - `readonly` private List, .)

, :

namespace Us.OtherProjects
{
   public class clsCommon : Us.Common.clsCommon
   {}
}

namespace Us.OtherProjects
{
   public static class clsMain
   {
         public static clsCommon CommonClsClassReferenceForGlobalUsage = new clsCommon();
         .
         .
         .
   }
}

namespace Us.OtherProjects
{
   public class clsOtherClass
   {
      .
      .
      .
         private void someMethod()
         {
            string something = clsMain.CommonClsClassReferenceForGlobalUsage.Foo();
         }
      .
      .
      .
   }
}

, , , , Jon Skeet ?

+5
2

. (, CopyFile, GetTimeStamp), . . System.Math.

, , ( /). .

, , . ( ) . Singleton (s) , , Logging Configuration ..

, , - 1 , , , .

+5

Common, Manager, Helper, . , . , .

- ( concurrency, ..). , , , .


" wannabe" , . , - ( ).


, , , SomethingManager?

, . , , "XManager" , "Manager" "X" "" , "". -. ? - . "" . / / ( , UI , -).


Hmmm... , , Us.Common {public (static?) class Strings {} public (static?) class Files {} public (static?) class Settings {}} ? , .

. - Logical cohesion .

+6

All Articles