Chapter 3:
To design a class, determine an object’s responsibilities and classify them as knowing responsibilities or doing responsibilities.
Knowing responsibilities: knowing the properties of the entity the object is modeling, knowing about other objects with which it needs to cooperate
Doing responsibilities: computing particular values, performing actions that modify its state, creating and initializing other objects, and controlling and coordinating the activities of other objects
Local variable: a method variable created as part of a method execution, used to hold intermediate results needed during the computation.
LOCAL VARIABLE:
· Defined inside a method
· Exists only while the method is being executed
· Must be initialized before being used; otherwise, a compiler error occurs
· Can be accessed only from the method
· Is only meaningful during execution of the method
· Contains some intermediate value needed only during execution of the method; its value is not part of the object’s state
INSTANCE VARIABLE:
· Defined outside any method
· Exists as long as the object exists
· Initialized in a constructor
· Can be accessed from any method in the class
· Has a meaningful value at any time during the life of the object, whether the object is actively doing something or not
· Represents a property of the object; its value is part of the object’s state
Main method: the top-level method that initiates execution of a system
Wednesday, November 01, 2006
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment