So I understand what a static method or field is, I am just wondering when to use them. That is, when writing code what design lends itself to using static methods and field
Here are some examples of when you might want to use static methods:
1) When the function doesn't make use of any member variables. You don't have to use a static method here, but it usually helps if you do.
2) When using factory methods to create objects. They are particularly necessary if you don't know the type to be created in advance: e.g.
class AbstractClass {
static createObject(int i) {
if (i==1) {
return new ConcreteClass1();
} else if (i==2) {
return new ConcreteClass2();
}
}
}
3) When you are controlling, or otherwise keeping track of, the number of instantiations of the class. The Singleton is the most used example of this.
4) When declaring constants.
5) Operations such as sorts or comparisons that operate on multiple objects of a class and are not tied to any particular instance.
6) When special handling has to be done before the first instantiation of an object.