01 introduction & overview

22
© IBM Corporation 2013 IBM Global Business Services Introduction & Overview Object Oriented Programming

Upload: bakkalibilal

Post on 24-Dec-2015

15 views

Category:

Documents


0 download

DESCRIPTION

01 Introduction & Overview

TRANSCRIPT

Page 1: 01 Introduction & Overview

© IBM Corporation 2013

IBM Global Business Services

Introduction & Overview Object Oriented Programming

Page 2: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 20132 July-2007Introduction & Overview

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

Page 3: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 20133 July-2007Introduction & Overview

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 object’s 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.

Page 4: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 20134 July-2007Introduction & Overview

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

Page 5: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 20135 July-2007Introduction & Overview

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 - Same code can be reused multiple times by using inheritance.

Page 6: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 20136 July-2007Introduction & Overview

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.

Page 7: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 20137 July-2007Introduction & Overview

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.

Page 8: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 20138 July-2007Introduction & Overview

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

Page 9: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 20139 July-2007Introduction & Overview

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

Page 10: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 201310 July-2007Introduction & Overview

Basic Building Blocks of Object Oriented Programs

Desktop PCAttributes

•Display type

•HDD capacity

•RAM size

•Processor Speed

Methods

Switch On

Switch Off

Class

Lenovo PCAttributes•Display type - LCD

•HDD capacity – 160GB

•RAM size – 1GB

•Processor Speed – Dual Core

Instance

Page 11: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 201311 July-2007Introduction & Overview

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.

Page 12: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 201312 July-2007Introduction & Overview

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

Page 13: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 201313 July-2007Introduction & Overview

Encapsulation

Benefits of EncapsulationEncapsulating 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.

Packaging an object’s 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.

Page 14: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 201314 July-2007Introduction & Overview

Encapsulation

Packaging an object’s 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.

Page 15: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 201315 July-2007Introduction & Overview

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.

Page 16: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 201316 July-2007Introduction & Overview

Inheritance

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

Page 17: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 201317 July-2007Introduction & Overview

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.

Page 18: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 201318 July-2007Introduction & Overview

Inheritance : Subclass and Superclass

•Superclass

•Subclass

Page 19: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 201319 July-2007Introduction & Overview

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)

•With Character Parameters

•(Concatenation Operation is performed)

Page 20: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 201320 July-2007Introduction & Overview

Access modifiers

Public componentsVisible to all direct access

Protected componentsOnly 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

Page 21: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 201321 July-2007Introduction & Overview

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.

Page 22: 01 Introduction & Overview

IBM Global Business Services

© IBM Corporation 201322 July-2007Introduction & Overview

Thank You

Questions