Discussion
Topic 1 Access methods
It is normal for a Java class to restrict
access to its class and instance variables. For example, if class X wants to get the value
of a variable in class Y, it would normally call a method (an accessor method) in
class Y to do this.
Although it is possible to read an instance
variable in a different object directly, like this:
int minutes = calendar.minutes;
We would normally use an accessor method,
like this:
int minutes = calendar.get (Calendar.MINUTE);
Working this way leads to a slight increase in
the complexity of every class, as accessor methods need to be provided to control access
to a number of variables.
So why is this way of working so widespread?
What advantages does it have?
Contribution for Discussion Topic 1 ?Access methods
Back
to top
RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg |