Notes Regarding Class Time2’s set and get Methods and Constructors
Time2
’s set and get methods are called throughout the class. In particular, method setTime
calls methods setHour
, setMinute
and setSecond
in lines 47–49, and methods toUniversalString
and toString
call methods getHour
, getMinute
and getSecond
in line 102 and lines 109–110, respectively. In each case, these methods could have accessed the class’s private data directly without calling the set and get methods. However, consider changing the representation of the time from three int
values (requiring 12 bytes of memory) to a single int
value representing the total number of seconds that have elapsed since midnight (requiring only 4 bytes of memory). If we made such a change, only ...
Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.