You are on page 1of 15

Chapter 2

Object-Oriented
Programming Concepts

FALL22
Safae Bourhnane
Chapter ILOs

 Understand the main object-


oriented concepts:
• Abstraction

• Cohesion

• Encapsulation

• Information hiding
Abstraction

 What is Abstraction?

 Creates a layer between the object


and the user
• Show only what is important to
the user
• The object is treated as a black
box
• What is wrong?
Abstraction

Examples
• Washing machine
• Coffee maker
• Computer

Other examples?
Cohesion
 Problem: putting too many functionalities into one object

 Cohesion means that various aspects of an object “fit together”


• Cohesion: interaction within a module
• Coupling: interaction between modules
Cohesion
 What is wrong?

 What is the solution?


Cohesion
 High Cohesion
Encapsulation

Allows the object to place boundaries around its properties and


functionalities

Does encapsulation ensure data protection


Question: and information hiding?
Encapsulation
 What is wrong?
Encapsulation
 How to make it more Object-Oriented?
Information Hiding
 Hiding of critical design decisions

 Difficult design decisions and decisions that are likely to change

 Hiding information isolates clients from requiring intimate knowledge of the design to
use a module, and from the effects of changing those decisions.
Information Hiding
 What is wrong?
Information Hiding – Access Control

The class has to expose only what is necessary to the Why do we need access control?
client programmer and keeps everything else hidden:
Access Control.

- To prevent client programmers from


accessing sensitive data.
- To allow the library designer to change
the internal workings of the class without
worrying about how it will affect the
client programmer.
Access Control – A look ahead
 Java makes use of explicit keywords to set boundaries for the classes, e.g. public,
private

• public means that the element can be available to everyone


• private means that no one has access to the element except the creator of the class.
Information Hiding
 Restrict access and modification of internal data through the use of accessors and
mutators

• Accessors/getters: public methods that give information about the state of the object

• Mutator/setter: public methods used to modify the state of an object without explicitly
showing how data gets modified

You might also like