A
ann
I am trying to understand scope and am getting a little confused. Say
I have a public class "Triangle" with private attributes and public
accessors. This class has attributes of type "Point". Point is
another public class in the same package as Triangle and it, too, has
public accessors. I'd like to allow a program outside the package to
create a Triangle, set the Point attributes, and then call a method in
the Triangle class that performs some calculation and returns a Point.
So far, so good.
The question is, what if I want the Point that is returned to not be
modifiable by this outside program. Do I have to create two Point
classes? Identical except one is public (and would be used to set the
Triangle attributes) and one is default package scope(and would be
returned from the calculation method)?
Thanks,
Ann
I have a public class "Triangle" with private attributes and public
accessors. This class has attributes of type "Point". Point is
another public class in the same package as Triangle and it, too, has
public accessors. I'd like to allow a program outside the package to
create a Triangle, set the Point attributes, and then call a method in
the Triangle class that performs some calculation and returns a Point.
So far, so good.
The question is, what if I want the Point that is returned to not be
modifiable by this outside program. Do I have to create two Point
classes? Identical except one is public (and would be used to set the
Triangle attributes) and one is default package scope(and would be
returned from the calculation method)?
Thanks,
Ann