Encapsulation
Encapsulation
Encapsulation
Encapsu..What?
Encapsulation
Encapsulation describes the ability of an object
to hide its data and methods from the rest of the
world - one of the fundamental principles of
OOP (Object Oriented Programming).
http://orafaq.com/glossary/faqglose.htm
What is..
Object A thing or concept (usually the
Class object)
Data The way in which that object is
defined – its attributes
Method The things that that object can do
- actions
Mouse class
Attributes
Size
Colour
Shape
Buttons
ConnectionType
Cost
Mouse Class
Methods
Leftclick
Right click
Scroll
Move pointer
Exercise
/**
*
* @author Annamarie Kelly
*/
public class SimpleClass {
private int m_number;
public int getNumber()
{
return m_number;
}
public void setNumber(int _newValue)
{
if(_newValue<0 || _newValue>10)
m_number = 0;
else
m_number = _newValue;
}
Protect the data
Data is now Safe
SimpleClass.java
SimpleClassTestHarness.java