Specifications
Sun Services
Java™ Programming Language
Module 2, slide 13 of 26
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Information Hiding
The solution:
Client code must use setters and
getters to access internal data:
MyDate d = new MyDate();
d.setDay(32);
// invalid day, returns false
d.setMonth(2);
d.setDay(30);
// plausible but wrong,
// setDay returns false
d.setDay(d.getDay() + 1);
// this will return false if wrap around
// needs to occur
+setDay(int) : boolean
+setYear(int) : boolean
+setMonth(int) : boolean
+getDay() : int
+getMonth() : int
+getYear() : int
MyDate
-day : int
-month : int
-year : int
Verify days in month










