Você está na página 1de 22

IBM Global Business Services

Introduction & Overview


Object Oriented Programming
IBM Corporation 2013

IBM Global Business Services

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

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

What is Object Oriented Programming (OOP) ?


The fundamental idea behind Object Oriented Programming (OOP) is to combine
both data and the functions (methods) those operate on that data into a single
unit. Such an unit is called Object, i.e. key principle of OOP is Data controlling
access to code.
Object orientation focuses on objects that represent either abstract or concrete
things in the real world. They are first viewed in terms of their characteristics,
which are mapped using the objects internal structure and attributes (data). The
behavior of an object is described through methods and events (functionality).
Objects form capsules containing the data itself and the behavior of that data.
Objects should enable you to draft a software solution that is a one-to-one
mapping of the real-life problem area.

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

Advantages of Object Oriented Programming


Better Programming Structure
Real world entity can be modeled very well
Stress on data security and access
Data encapsulation and abstraction
Reduction in code redundancy

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

Advantages of the Object-Oriented Approach


Abstraction

Modeling real world entities and processes in a more natural


way.

Ecapsulation - Encapsulation means that the implementation of an object is


hidden from other components in the system, so that they
cannot make assumptions about the internal status of the
object and therefore dependencies on specific
implementations do not arise.

Inheritance

- Inheritance defines the implementation relationship between classes, in


which one class (the subclass) shares the structure and the behavior
defined in one or more other classes (superclasses).

Polymorphism - Polymorphism (ability to have multiple forms) in the context of


object technology signifies that objects in different classes
have different reactions to the same message..

Code Reuse
5

- Same code can be reused multiple times by using inheritance.

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

Abstraction : Ignore the details


In philosophical terminology, abstraction is the thought process wherein ideas are
distanced from objects.
In computer science, abstraction is a mechanism and practice to reduce and factor
out details so that one can focus on few concepts at a time.
Abstraction uses a strategy of simplification, wherein formerly concrete details are
left ambiguous, vague, or undefined.

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

Modularization : Break into pieces


A module can be defined variously, but generally must be a component of a larger
system, and operate within that system independently from the operations of the
other components.
Modularity is the property of computer programs that measures the extent to which
they have been composed out of separate parts called modules.
Programs that have many direct interrelationships between any two random parts
of the program code are less modular than programs where those relationships
occur mainly at well-defined interfaces between modules.

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

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).

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

Basic Building Blocks of Object Oriented Programs


Class A class is a blueprint that defines the variables and the methods common
to all objects of a certain kind.
Gives a general description of objects (blueprint).
Establishes status types (attributes) and behavior (methods)
When a real world entity is modeled into OOP world then it is known as Class,
characteristics as attributes and functionality as methods

Object An object is a software bundle of variables and related methods (Also


known as instance)
Reflection of real world
Specific instance of a class

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

Basic Building Blocks of Object Oriented Programs

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

Processor Speed Dual Core

Switch On
Switch Off

10

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

Visibility Sections in a Class


All components of a class must belong to a visibility section. Components can
be public, protected or private.
Public components form the external interface of the class they are visible to
all users of the class as well as to methods within the class and to methods of
subclasses.
Protected components form the interface of the class to its subclasses they are
visible to methods of the heirs of the class as well as to methods within the class.
Private components can only be used in the methods of the class itself.

11

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

Types of Attributes and Methods


Instance vs. Static
Attributes

Instance Attributes

Static Attribute (Also


known as class
attributes0

Existence ?

One per instance

Only one per class

Instance vs. Static


Methods

Instance Methods

Static Methods (Also


known as class
attributes0

Capability ?

Can use both static and


instance components in
the implementation part

Can only use static


components in the
implementation part

12

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

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

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

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

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

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

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

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

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

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

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

Inheritance : Subclass and Superclass

Superclass

Subclass

18

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

Inheritance with Polymorphism


Polymorphism
Polymorphism just means that different objects can respond to the same message
in different ways.

METHOD ADD

With Numeric Parameters


(Addition Operation is
performed)

19

Introduction & Overview

With Character Parameters


(Concatenation Operation is
performed)

July-2007

IBM Corporation 2013

IBM Global Business Services

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

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

Inheritance with Polymorphism


In Greek Poly means 'many' and 'morph'
means form.
This ability of different objects to respond,
each in its own way, to identical messages is
called polymorphism.
If a Dog is commanded to talk(), it may emit a
bark, while if a Pig is asked to talk(), it may
respond with an oink. Both inherit talk() from
Animal, but their subclass methods override
the methods of the superclass, known as
overriding polymorphism. Adding a walk
method to Animal would give both Pig and
Dog objects the same walk method.

21

Introduction & Overview

July-2007

IBM Corporation 2013

IBM Global Business Services

Thank You
Questions

22

Introduction & Overview

July-2007

IBM Corporation 2013

Você também pode gostar