Escolar Documentos
Profissional Documentos
Cultura Documentos
Course Objectives
Upon completion of this course, you should be able to:
Recognize the concept of Object Oriented Programming (OOP)
Identify the features of Object Oriented Programming & its Advantages
Analyze the basic building blocks of Object Orientated Programming
Encapsulation, Inheritance, Polymorphism
July-2007
July-2007
July-2007
Inheritance
Code Reuse
5
July-2007
July-2007
July-2007
Information hiding
Separate the implementation and the function.
The principle of information hiding is the hiding of design decisions in a computer
program that are most likely to change, thus protecting other parts of the program
from change if the design decision is changed.
Protecting a design decision involves providing a stable interface which shields the
remainder of the program from the implementation (the details that are most likely
to change).
July-2007
July-2007
Class
Desktop PC
Attributes
Display type
HDD capacity
RAM size
Processor Speed
Instance
Lenovo PC
Attributes
Display type - LCD
HDD capacity 160GB
RAM size 1GB
Methods
Switch On
Switch Off
10
July-2007
11
July-2007
Instance Attributes
Existence ?
Instance Methods
Capability ?
12
July-2007
Encapsulation
Packaging an objects variables (attributes) within the protective custody of its methods.
called encapsulation. For ex. if we consider an instance as a cell the variables (attributes)
form the core nucleus and the methods surround these attributes.
Benefits of Encapsulation
Encapsulating related variables and methods into a neat software bundle is a simple yet
powerful idea that provides two benefits to software developers:
Modularity: The source code for an object can be written and maintained independently of
the source code for other objects. Also, an object can be easily passed around in the
system. You can give your bicycle to someone else, and it will still work.
Information-hiding: An object has a public interface that other objects can use to
communicate with it. The object can maintain private information and methods that can be
changed at any time without affecting other objects that depend on it.
13
July-2007
Encapsulation
Packaging an objects variables (attributes) within the protective custody of its
methods. called encapsulation.
For ex. if we consider an instance as a cell the variables (attributes) form the
core nucleus and the methods surround these attributes.
14
July-2007
Benefits of Encapsulation
Encapsulating related variables and methods into a neat software bundle is a
simple yet powerful idea that provides two benefits to software developers:
Modularity
The source code for an object can be written and maintained independently of the
source code for other objects.
An object can be easily passed around in the system.
You can give your bicycle to someone else, and it will still work.
Information-hiding
An object has a public interface that other objects can use to communicate with it.
The object can maintain private information and methods that can be changed at any
time without affecting other objects that depend on it.
15
July-2007
Inheritance
Inheritance
The term inheritance refers to the fact that one class can inherit part or all of its structure and
behavior from another class. The class that does the inheriting is said to be a subclass of the
class from which it inherits. If class B is a subclass of class A, we also say that class A is a
superclass of class B. A subclass can add to the structure and behavior that it inherits. It can
also replace or modify inherited behavior (though not inherited structure). The relationship
between subclass and superclass is sometimes shown by a diagram in which the subclass is
shown below, and connected to, its superclass.
16
July-2007
Inheritance
The term inheritance refers to the fact that one class can inherit part or all of its
structure and behavior from another class.
The class that does the inheriting is said to be a subclass of the class from which
it inherits.
If class B is a subclass of class A, we also say that class A is a superclass of
class B.
A subclass can add to the structure and behavior that it inherits.
It can also replace or modify inherited behavior (though not inherited structure).
The relationship between subclass and superclass is sometimes shown by a
diagram in which the subclass is shown below, and connected to, its superclass.
17
July-2007
Superclass
Subclass
18
July-2007
METHOD ADD
19
July-2007
Access modifiers
Public components
Visible to all direct access
Protected components
Only visible within their class and within
the subclass
Private components
Only visible within the class
No access from outside the class, not
even from the subclass
20
July-2007
21
July-2007
Thank You
Questions
22
July-2007