Encapsulation

32,006 views 14 slides Dec 01, 2011
Slide 1
Slide 1 of 14
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14

About This Presentation

A short presentation about Encapsulation
OCJP Batch 27


Slide Content

Githushan Gengaparam Madhusoothanan Lakshitha Imbulpitiya Sudheera Karunaratne

Introduction Object Oriented Programing (OOP) concepts

Introduction Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. Encapsulation also can be described as a protective barrier that prevents the code and data being randomly accessed by other code defined outside the class .

Importance of encapsulation To hide the internal implementation details of the class Can safely modified the implementation without worrying breaking the existing code that uses the class Protect class against accidental/ willful stupidity Keeps class tidy by keeping the visible fields to a minimum Easier to use and understand

Why need encapsulation? In object-oriented programming data encapsulation is concerned with; Combining data and how it's manipulated in one place : This is achieved through the state (the private fields) and the behaviors (the public methods) of an object. Only allowing the state of an object to be accessed and modified through behaviors: The values contained within an object's state can then be strictly controlled. Hiding the details of how the object works: The only part of the object that is accessible to the outside world is its behaviors. What happens inside those behaviors and how the state is stored is hidden from view .

benefits The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this feature Encapsulation gives maintainability, flexibility and extensibility to the code .

Benefits of having encapsulation The fields of a class can be made read-only or write- only A class can have total control over what is stored in its fields The users of a class do not know how the class stores its data. A class can change the data type of a fields, and a users of the class do not need to change any of their code

maintainability Encapsulation draws a boundary around a set of data and method. This allows a developer to use the code without having to know how it works, but with what input data and its input data range and with what it returns.

flexibility Encapsulation makes the code easier to visualize. This means codes can be arranged “visually” before implementing.

extensibility Makes long term development easy. Updates can be made by changing the encapsulated part without changing the input and output formats.

Library System + setBaseFine (float) : void + toString () : String + abstract getFine ( int ) : float Item <<abstract>> # code : String # title : String # year : int # baseFine : float + toString () : String + getFine ( int ) : float Book <<entity>> - author : String - publisher : String + toString () : String + getFine ( int ) : float Video <<entity>> - producer : String - distributer : String - cast : String - duration: float + toString () : String + getFine ( int ) : float Audio <<entity>> - artist: String - g enre : String

Conclusion Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods . The main benefit of encapsulation is the ability to modify the implemented code without breaking the code of others who use the implemented code.

Conclusion Encapsulation makes the programing code;