How should you determine static methods or instance methods?
If an entity have a state you will be representing the state with variables on a class and the instance of the class (object) represents an instance of that entity.
All I am trying to explain in next paragraph is "what is State". If the entity have a state use instance method else use static method. Another reason to make instance method is
polymorphism.
State: A house have a propery called Occupied:boolean; House have a behaviour called getNumberOfOccupants. The property Occupied varies with every instance of House. So it is better to keep Occupied as an Instance variable.
getNumberOfOccupants first check whether house is occupied. If not occupied it returns zero, else returns numberOfOccupants:int (another Property)
Here numberOfOccupants and occupied are instance variables which are maintaining the state of an object. Since getNumberOfOccupants method relies on state of the object, this method sould be an instance method. In java this rule is contracted through language.
Polymorphism: Suppose you have a universal remote control which can be used to power off several systems like Tape player, DVD player, TV, Video Tape Player. You can off one or more systems at a time. The super class (abstract) have a method powerOff:void. The Object of type Remote gain access to all instances of System (Tape player, DVD player, TV, Video Tape Player) and invoke the method powerOff. Here powerOff is an instance method. The beauty here is Remote don't have to know the type(subclass) of system.
You couldn't have implemented this "dynamic(runtime binding) polymorphism" if you kept powerOff as static method.
[ December 12, 2005: Message edited by: jiju ka ]