Human Computer Interaction - An Introduction
Human Computer Interaction - An Introduction
Lecture 1:
Object Oriented Programming
- an Introduction
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
Function P Function Q
Application is divided into 4 modules Module C carries out 3 tasks (X,Y,Z) Procedure Y calls function P and Q
Real-world objects share two characteristics: They all have state and behavior
DOG BICYCLE
State ? State ?
Behavior ?
Behavior ?
Software Object
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.
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
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.
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
• 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
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.
Creating subclass - at beginning of class use the extends keyword, followed by name of the
class to inherit from:
Interface IPrinter
Implementation_1
+5V
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);
}
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.
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