Transcript Week 04

CS 2511
Fall 2014
Features of Object Oriented Technology

Abstraction
• Abstract class
• Interfaces

Encapsulation
• Access Specifiers
• Data Hiding

Inheritance

Polymorphism
Encapsulation
A software development technique that consists of isolating
a system function or a set of data and operations on those
data within a module and providing precise specifications
for the module -IEEE

Principle of binding processes (Member Method) and data
(Member Data) to form an integrated unit is the essence of
Encapsulation


Implemented by using the concept of Class
Access/Visibility Specifiers
Used for accessibility of data member
and member methods from within and
outside the class boundary
 Examples:

• Private
• Public
• Protected
• Default / Package
Data Hiding
• Process of hiding the members from outside the class
• Implemented by the concept of “Private” access specifiers
• Can be accessed only by the member methods of that class where it
is defined
• Data hiding is an important feature of OO programming which allows
the data member to be kept safe
Accessors and Mutators

Constructor methods: A new instance of an object is
created by calling a constructor method. Values can be
passed to a constructor method to set the initial state of an
object.

Accessor methods: For every private field we can create a
public method that will return its value.

Mutator methods: For every private field we can create a
public method that will set its value. If you want a private field
to be read only do not create a mutator method for it.
DATE CLASS
• Present in the java.util package.
•Some of the methods:
• boolean after (Date when)
• boolean before (Date when)
• int compareTo(Date anotherdate)
• long getTime()
•Void setTime()
• Date d = new Date (y, m, d);
INTERFACE IN UML DIAGRAMS
COMPARABLE INTERFACE
• Collections.sort(list)
• int compareTo (Class obj)
COMPARATOR INTERFACE
• Changing the sort order
• int compare (T obj1, T obj2)