Lec 20
Lec 20
I Semester 2008-09
Lecture 20
1
What kind of problems did we solve till now
2
Which methodology we used
The methods are designed in total isolation from ... the property of data to
be processed
3
Which methodology we used
The methods are designed in total isolation from the property of data to be
processed
4
A fact of real life
5
Examples
6
Aim : first to model the problem and then solve it ?
7
Modeling the problem
1. For student records will you need the family history of the student ?
2. For Bank accounts will you need to know the height of the account holder ?
3. For points, will you need to know the source from where they were generated
?
NO
We just focus on those features which are relevant to the problem
8
Abstraction : Ist step in modeling the problem
You have been using it for long (without perhaps noticing it consciously)
9
Let us review the Examples again
10
Let us review the Examples again
11
Maintaining student records
12
Maintaining student records
13
Maintaining student records
14
Maintaining Bank accounts
15
Maintaining Bank accounts
16
Computing some geomteric structure for a set of points
• x coordinate, y coordinate
and methods for points
17
Computing some geomteric structure for a set of points
• x coordinate, y coordinate
and methods for points
18
Crucial Observation
whenever we think of the (attributes of the) data, ... the thoughts of the methods
on them comes automatically in our mind.
So it is useful to think of (the attributes of) data in conjunction of the methods
which work on them.
19
Crucial Observation
whenever we think of the (attributes of the) data, the thoughts of the methods on
them comes automatically in our mind.
So it is useful to think of (the attributes of) data in conjunction of the methods
which work on them.
20
Crucial Observation
whenever we think of the (attributes of the) data, the thoughts of the methods on
them comes automatically in our mind.
So it is useful to think of (the attributes of) data in conjunction of the
methods which work on them.
21
Objects
Objects are self contained entity which has its own collection of
• attributes
• methods to access them, manipulate them and compute some functions on
them.
22
Encapsulation : one of the fundamental principle of OOP
The ability of an object to be a container (or capsule) for its attributes (i.e. data
variables) and its related methods (i.e. functions).
23
What is a class ?
Definition : A class specifies the attributes (data) and methods (actions) that
objects can work with.
It is just a template or prototype for each of many objects belonging to the class.
24
How to describe Class for Point
•
•
25
Class for Point
attributes
• x-coordinate
• y-coordinate
The methods dealing with Point :
set x-coordinate or y-coordinate of a point
get x-coordinate and y-coordinate of a point
Square of distance from origin
translation of a point
26
Class for Point
27
How to create an object
28