Specifications

Sun Services
Java™ Programming Language
Module 2, slide 12 of 26
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Information Hiding
The problem:
MyDate
+day : int
+month : int
+year : int
Client code has direct access to
internal data (d refers to a MyDate
object):
d.day = 32;
// invalid day
d.month = 2; d.day = 30;
// plausible but wrong
d.day = d.day + 1;
// no check for wrap around