Provides static methods or properties that you do not need to instantiate to access by means of the static method. All callers can use the same class (not instantiated) or an object (instantiated only once) that can be applied to the scene:
1) Each caller shares data and works together.
2) An object can only be instantiated once.
3) The life cycle of the called object is independent of the caller. Or, the object has a global life cycle, which continues to work, providing only one interface to the caller.
An instance of a class is maintained by the class itself and provides a way to take an instance.
Typical code:
Public classtestclass{//Instances of Maintenance Private StaticTestClass instance; //static methods for externally available get instances Public StaticTestClass Instance {Get { if(Instance = =NULL) Instance=NewTestClass (); returninstance; } }}
Application Examples:
The definition of DependencyProperty in WPF
/** Two ways to use * 1) use dictionary in the form of a total class to record all properties registered by the static registration method of the class * 2) to generate a new object **/ Public classdependencyproperty{Internal Staticdictionary<Object, dependencyproperty> Registereddps =Newdictionary<Object, dependencyproperty>(); Internal stringName; Internal ObjectValue; Internal Objecthashcode; //constructor Function PrivateDependencyProperty (stringName, type propertyname, type OwnerType,ObjectDefaultValue) { This. Name =name; This. Value =DefaultValue; This. Hashcode = name. GetHashCode () ^Ownertype.gethashcode (); } //Registration Function Public StaticDependencyProperty Register (stringName, type PropertyType, type ownertype,ObjectDefaultValue) {DependencyProperty DP=NewDependencyProperty (name, PropertyType, OwnerType, DefaultValue); Registereddps.add (DP. Hashcode, DP); returnDP; }}
Object-Oriented Programming note--static