c# - How to abstract a static classes -
i have static class. can modify , make extends interface\abstract class.
it contains
- lots of readonly , consts members.
- staic methods.
in order make code testable, want to
- separate dto , manager.
- abstract each of them. how classes static?
in opinion there 2 things static classes for:
- providing global functions/algorithms (that should not depend on state - a.k.a pure functions)
- hold global data
if model methods in there pure can test right away. global data (your constants , read-only members) on other hand don't need testet should produced said methods.
so if static methods use global data class refactor them include data parameters method, overload simple wrappers feeding global data , test new - pure - functions. take care include things database-data or system-times (datetime.now) , similar side-effect data methods well.
if parameterlist gets big refactor method class some/most of parameters encapsulated new classes fields - remember s solid (single responsibility) - clutter "mystaticglobals"-class/singelton if test parts in seperation.
Comments
Post a Comment