01-11-2012, 03:18 PM
Encapsulation Data Hiding Abstraction
Encapsulation.ppt (Size: 53.5 KB / Downloads: 25)
The Inner Class
This class responds to the New Ball button
It's Private
It is only defined within our class
It works only with this button
It is anonymous
Under JDK we'll see a weird class file name
Visibility and Inheritance
Visibility Modifiers work with Inheritance
Public
Inherited
Protected
Inherited
Private
Not Inherited
Class Design - Accessing Objects
Often we want to treat our state information as read-only
We can provide getData() methods
Accessors
We could provide access to the state data directly by making it public
Violates Encapsulation & Data hiding
Class Design - Changing Objects
Changing data is generally done through controlled interfaces
By forcing the users and communicators with our objects to go through an interface we can implement appropriate checks and controls.
Data Hiding
Uncouple the details from the concept
If we define a class, and know that the class has specific methods, we can use those methods, rather than manipulating the class's data directly
Public
Almost every class is declared Public
No access restrictions to data
Well, read-only if final
No access restrictions to methods
In General:
Declare classes public
A good idea for our API methods
Not a good idea for data
Provide a method to read or change the value