(^292) | Object-Oriented Software Design and Implementation
Julian Day Formula
intRes1 = 2-year/100+year/400
intRes2 = (int) (365.25year)
intRes3 = (int) (30.6001(month+1))
julianDay = intRes1+intRes2+intRes3+day+1720994.5
class
Date
Astronomy
Te x t
Figure 6.8 Who Would Use Similar Data?
Is one representation better than another? We can’t answer that question without knowing
how the class might be used in a problem. However, the beauty of abstraction and encap-
sulation is that the internal representation of the fields can be changed and the program that
uses the class remains oblivious to the modification.
Responsibilities as Methods
Each responsibility on the CRC card can be implemented by a method in the class. If we
know the information that is needed and what is returned by each one, then the design is
straightforward. An observer naturally returns a value, so we implement observers as Java
value-returning methods. A transformer is typically a void method. Iterators may be either
value-returning or void, but we won’t consider them until we introduce arrays in Chapter 11.
If a responsibility implicitly refers to an object, then it should be implemented as an in-
stance method. Observers, transformers, and iterators are always instance methods. They