0% found this document useful (0 votes)
78 views30 pages

Human Computer Interaction - An Introduction

The document provides an introduction to object-oriented programming (OOP). It discusses procedural programming versus OOP, defining objects as having state and behavior. Classes are defined as blueprints for creating objects. OOP principles like encapsulation, inheritance, and polymorphism are covered. The document uses examples like a lamp and DVD player to illustrate the states and behaviors of real-world objects that can be modeled in code. It also discusses how objects encapsulate data and methods through a public interface.

Uploaded by

Suneel Dalavaie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views30 pages

Human Computer Interaction - An Introduction

The document provides an introduction to object-oriented programming (OOP). It discusses procedural programming versus OOP, defining objects as having state and behavior. Classes are defined as blueprints for creating objects. OOP principles like encapsulation, inheritance, and polymorphism are covered. The document uses examples like a lamp and DVD player to illustrate the states and behaviors of real-world objects that can be modeled in code. It also discusses how objects encapsulate data and methods through a public interface.

Uploaded by

Suneel Dalavaie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

NPTEL Course on

Human Computer Interaction


- An Introduction
Dr. Pradeep Yammiyavar Dr. Samit Bhattacharya
Professor, Assistant Professor,
Dept. of Design, Dept. of Computer Science
IIT Guwahati, and Engineering,
Assam, India IIT Guwahati, Assam, India

Indian Institute of Technology Guwahati


Module 9:
Object Oriented Programming

Lecture 1:
Object Oriented Programming
- an Introduction

Dr. Pradeep Yammiyavar

The inputs & assistance to this module by Mr.Yogesh Deshpande, PhD scholar at HCI-
UE- Lab, IITG, (2010 – 2013) is acknowledged with thanks
Overview
• Procedural Programming Paradigm - PPP
• Object-Oriented Programming Paradigm - OPP
• Objects
•State and Behavior
• Software Objects - Fields and Methods
• Data Encapsulation
• Public Interface
• Object-based application
• Benefits of object-based application development
• Classes
• Definition
• Blueprint of similar object
• Instantiating objects from class - example
• Object-Oriented Principles
•Encapsulation
•Inheritance and Interfaces
•Polymorphism
• Packages and API
Procedural Programming Paradigm (PPP)
• In this paradigm (functional paradigm) the programming unit is a function.
• Program is divided into self-contained and maintainable parts called
‘modules’ (e.g. A,B,C,D).
• A module contains procedures - self-contained code that carries out a single
task (e.g. X,Y,Z).
• A function (e.g. P, Q) is a self-contained code returning value to the calling
procedure (e.g. Y).
• In PPP all computations are done by applying functions.
• Procedural paradigm separates data of program from instructions that
manipulate the data.
Application Module C Procedure Y

Module A Module C Procedure X

Function P Function Q

Module B Module D Procedure Y Procedure Z

Application is divided into 4 modules Module C carries out 3 tasks (X,Y,Z) Procedure Y calls function P and Q

Data in data code Data out

Function (processes the data)


Object Oriented Programming Paradigm (OOPP)
• Paradigm describes a system as it exists in real life based on interactions among real objects.
• Application is modeled as collection of related objects that interact and do your work (task).
• The programming unit is a class representing collection of similar real world objects.
• Programming starts with abstraction of useful real world objects and classes.
• Application is divided into multiple packages (e.g. A,B,C,D).
• A package is a collection of classes (e.g. P,Q,R) fulfilling group of tasks or functionality.
• A class is an encapsulated(data + code) definition of collection of similar real world objects.
• OOPP binds together data and the instructions that manipulate the data into a class.
Class R
Application Package B
m1()
Class m2()
Package A Package B
P m7()
Data m3()
x,y,z
Class Class m6()
Package C Package D Q R m4()
m5()

Application is collection of 4 packages Package B contains 3 classes (P,Q,R) Object A


Object X of Class R Class R encapsulates 7 methods( m1.. m7)
and 3 attributes ( x, y, z)
Data
Message to invoke m4() 3,8,1 Data / Object out
00
(Ask object X to do task m4)
Object (encapsulates data+code)
Objects
Objects are key to understanding object-oriented technology. Look
around right now and you'll find many examples of real-world objects
Objects

Real-world objects share two characteristics: They all have state and behavior

DOG BICYCLE

State Name State Current Gear


Color Current Speed
Breed Current Pedal Cadence ( rhythm )
Hungry
Behavior Barking Behavior Changing gear
Fetching Changing pedal cadence
Wagging Applying brakes
Tail
Objects
Try and identify the State & behavior of the two objects .

TABLE LAMP DVD PLAYER

State ? State ?

Behavior ?
Behavior ?

Answer in the next slide


Objects

TABLE LAMP DVD PLAYER

State On/Off State On /Off


Current Volume
Current Station
Behavior Turning
Beha Turn on
On
vior Turn off
Turning
Increase volume
Off
Decrease volume,
Seek
Scan
Tune
Software Objects - fields and methods

Software Object

An object stores its state / information in fields (attributes


) and exposes its behavior through methods ( member
functions )
Objects - Data Encapsulation

Objects methods can only change object's internal state.


Hiding this internal state & requiring all interaction to be
performed through an object's methods is known as data
encapsulation
Objects – Data Encapsulation

Window Object

Change_width()

Change_hei
ght()
Height as real = Change_locati
32.15 on()
Width as real =
10.15
Color as string =
“Red”
Location as point =
15,25

Maximize() Minimize()
Objects - Public Interface
Other objects can change the state of an object by using
only those methods that are exposed to the outer world
through a public interface. This help in data security.

Object is an encapsulation of data (attributes) as well


as methods (functions)
Private Public
initialize() Volume-()
Public Public
Curr volume
TurnOff()
Turn On Curr channel TurnOn()
Volume Power private
Etc ………. modulate()
Turn Off Private
decode () Public
Public Volume+()
SetChannel()
Interface IA
Object Set Top Box
Objects - Public Interface

Other objects can change the state of an object by using only


those methods that are exposed to the outer world through an
public interface. This help in data security.

Object is an encapsulation of data (attributes) as well as


methods (functions)

Public Public
getX() getY()
Private
Setx(real) Average()
Sety(real) X,Y,Z, public
Setz(real) Avg getZ()
Public
Getx() SetZ()
Gety() Public
Getz() Public SetX()
SetY()

Interface IA
Object A
Object-based application
Power
Circuit
Turn
Interface On/OFF
IPowerCircuit

Receiver

Tuner Tuning
Interface
IAmplifier

IF
Amplifier

Audio
Amplifier + -
Interface
IAudio Volume+ Volume-
Electronic Components Connectors / Interfaces User Interface
Benefits of object-based application development
• Modularity:
Source code for an object can be maintained independently in a class. Once
created, an object can be easily passed around inside the system.
E.g. ClassMaths, Class string , ClassWindow etc
• Information-hiding:
By interacting only with an object's methods, the details of its internal
implementation remain hidden from the outside world. E.g. Interface IMaths ,
Interface IString Interface IWindow
• Code re-use:
If an object already exists (perhaps written by another software developer), you
can use that object in your program. This allows specialists to
implement/test/debug complex, task-specific objects, which you can then trust
to run in your own code.
e.g. Standard Classes available packages which can reused using their
interfaces.
• Pluggability and debugging ease: If a particular object turns out to be
problematic, you can simply remove it from your application and plug in a different
object as its replacement. This is analogous to fixing mechanical problems in the
real world. If a bolt breaks, you replace it, not the entire machine.
Class
Collection of objects that share common attributes and
behavior (methods)

Airplanes
Flowers
Animals

Vehicles
Animals
Stationary

Humans
Birds
Class - Structure

Class Animal Class Vehicle

Attributes Attributes

Behavior Behavior
Class - Blueprint of similar object

Factory of cycles of same make and model with same features and same
components . Built from same blueprint. This blueprint is called a
Class. In object-oriented
Class Cycle terms, we say that your
Used to create all other cycles cycle is an instance of
the class of objects
known as cycles

A class is the
blueprint from which
individual objects are
created.

The attributes and


operations defined by a
class are for its objects,
not for itself.

A class is a logical
construct, an object has
physical reality.
Class Definition – Example
Classes are passive and which do not Objects
Cycle1
communicate but are used to create
&
(instantiate) objects which interact. Cycle2

The responsibility of creating and using new changeCadence changeCadence


Cycle objects belongs to some other class in
your application. printStates
changeGear changeGear
class Cycle Cadence=10 Cadence=15
{ int cadence = 0; Speed=5kph Speed=2kph
int speed = 0; Gear=3 Gear=4
int gear = 1;
speedUp speedUp
applyBrakes applyBrakes
void changeCadence(int newValue)
{ cadence = newValue; }

void changeGear(int newValue)


{ gear = newValue; }
Class Cycle
void speedUp(int increment)
{ speed = speed + increment; }
int Cadence Represents
int Speed State
void applyBrakes(int decrement)
int Gear
{ speed = speed - decrement; }
void changeGear(int)
void printStates()
{ System.out.println("cadence:"+cadence+"
void printStates(int) Defines Interaction
speed:"+speed+“ gear:"+gear); } void speedUp(int) With World viz interface
} void applyBrakes(int)
cycle1 and cycle2 are instances of Class Cycle void changeCadence()
Instantiating objects from class
Cycle Demo class that creates two separate Main Class - Is a class that contains one method,
cycle objects and invokes their methods: called main. The main method contains a series of
instructions to create objects and to tell those
Class CycleDemo objects to do things.
{ Setting an Application's Entry Point
public static void main(String[] args)
{ // Create two different Bicycle
objects Define Main Class
Class Math Class with main() method
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();
Class Stat
// Invoke methods on those objects
bike1.changeCadence(50); Class Draw Create instances of
bike1.speedUp(10); required objects
bike1.changeGear(2); Interface IMath
bike1.printStates();
Interface IMath
bike2.changeCadence(50); Write instructions for
Interface IMath
bike2.speedUp(10); object communication to
bike2.changeGear(2); build applications
bike2.changeCadence(40); Java APIs
bike2.speedUp(10);
bike2.changeGear(3); Java Packages
bike2.printStates();
Delete objects created
}
}
This program is stored in file Programming Support
CycleDemo.java
Object-Oriented Principle – Encapsulation

• Encapsulation is the mechanism that binds together the code and the data
it manipulates, and keeps both safe from outside interference and misuse

Private Area
No Entry
X
Private Data

Private Functions

Public Area

Entry Allowed Public Data

Public Functions
Object-Oriented Principle – Inheritance
Inheritance is the process by which one object acquires the properties of another object.
By use of inheritance, an object need only define all of its characteristics that make it
unique within its class, it can inherit its general attributes from its parent. This will be
clear from the following example
Mountain bikes, road bikes, and Object-oriented
tandem bikes all share the programming allows
characteristics of bicycles classes to inherit commonly
(current speed, current pedal used state and behavior
cadence, current gear). from other classes.

Yet each has some features that In this example, Bicycle


makes them different: tandem now becomes the
bicycles have two seats and two superclass of MountainBike,
sets of handlebars; road bikes RoadBike, and TandemBike.
have drop handlebars; some
mountain bikes have an
additional chain ring, giving
them a lower gear ratio.

Creating subclass - at beginning of class use the extends keyword, followed by name of the
class to inherit from:

class MountainBike extends Bicycle


{
// new fields and methods defining a mountain bike would go here
}
Interfaces
• Public methods form the object's interface with the outside world
• Interface is a group of related methods with empty bodies ( pure virtual functions )

Menu- Publicly Available Items


Implementation_1
Dosa Client_1
Class Soiree Idli
Hotel Tea
Coffee
Ice-Cream
Bournvita
Pepsi

Class Office Soup


Canteen Pudding

Implementation_2 Interface IKitchen


• constant - should not change Client_2
• defines behavior
• does not have implementation
• client not bothered of
implementation
Interfaces
• Public methods form the object's interface with the outside world
• Interface is a group of related methods with empty bodies ( pure virtual functions )

Interface IPrinter
Implementation_1
+5V

Class Dot Matrix Gnd


X
X
TxD
Uses
Iprinter
RxD
to connect
DTS
CTS
Class InkJet X

Implementation_2 CPU
Class as implementation of interface
• A bicycle's behavior, if specified as an interface, might appear as follows
e.g. Class Soiree implements IKitchen
Class Bicycle implements IBicycle
{
int cadence = 0;
int speed = 0;
int gear = 1; IBicycle
void changeCadence(int newValue)
{ cadence = newValue; }
Interface IBicycle
{
void changeGear(int newValue) void changeCadence(int
{ gear = newValue; } newValue);

void speedUp(int increment) Implementation void changeGear(int newValue);


in Class
{ speed = speed + increment; }
void speedUp(int increment);

void applyBrakes(int decrement) void applyBrakes(int decrement);


{ speed = speed - decrement; }
void printStates()
void printStates() }
{
System.out.println("cadence:"+cadence+"
speed:"+speed+" gear:"+gear); }

}
To implement interface, the name of your class would change (to a particular brand of bicycle, for
example, such as ACMEBicycle), and you'd use the implements keyword in the class declaration
Interfaces define an application • An interface makes a class formal
about the behavior it promises to provide.

• Interfaces form a contract between the


class and the outside world and this
A Uses IA
Implements IB contract is enforced at build time by the
compiler.

• If your class claims to implement an


interface, all methods defined by that
interface must appear in its source
Implements IA code
before the class will successfully
compile. Unused
Uses IB E

Implements IC
Server Object Client Object
Implements ID C Implements IE
Uses IC

Uses ID
D
Object-Oriented Principle – Polymorphism
Polymorphism (from Greek, meaning ‘many forms’) is a feature that
allows same interface
(method name) to be used for a multiple class of actions depending on
context.
Examples shows same
name of method i.e.
ANIMAL
sound() but different
sound() implementations in CAT
and DOG

CAT DOG
sound() sound()
{ {
meow bark
} }
Packages and API
• A package is a namespace that organizes a set of related classes and interfaces
like a folder
• Software written in the Java programming language can be composed of hundreds or
thousands of reusable classes, it makes sense to keep things organized by placing
related classes and interfaces into packages.
• Java Platform provides Class library which has huge number of classes organized in
packages which is also called API. There are literally thousands of classes to
choose from. This allows you, the
Application Programming Interface (API) programmer, to focus on the design of your
(Standard nuts and bolts) particular application, rather than the
infrastructure required to make it work.
Class Library as collection of packages

Java.awt
Application_1

Java.util
Java APIs

Java.swing Application_2

Java.rmi

Java.sql
Application_3

Java.security
References
Books
• The Object-Oriented Thought Process by Matt Weisfeld, Publisher: Addison-Wesley
Professional
• Head First Object-Oriented Analysis & Design by Gary Pollice, David West, Brett D
McLaughlin , Publisher: Shroff O Reilly
• Experiencing Object Oriented Concepts: For Beginners by John E. Mathew

Ueful Links

http://scg.unibe.ch/archive/osg/Nier89aSurveyOfOOConcepts.pdf

http://www.codeproject.com/Articles/15874/Understanding-Object-Oriented-Concepts

http://www.slideshare.net/bgjeecourse/objectoriented-concepts-5576132

http://www.youtube.com/watch?v=3bMsY5a7cBo

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy