OOP - Lecture 1
OOP - Lecture 1
OOP - Lecture 1
OBJECT ORIENTED
PROGRAMMING (JAVA)
LECTURE 1
1
MY DETAILS
2
Object Oriented Programming
3
Before OO Programming
Simple, non-OOP programs may be one "long"
list of statements (or commands).
More complex programs will often group smaller
sections of these statements
into functions or subroutines each of which might
perform a particular task.
With designs of this sort, it is common for some
of the program's data to be 'global', i.e.
accessible from any part of the program.
4
Before OO Programming contd
Data usually separated from the operations that
acts on the data.
Data security is to some extent a major problem.
As programs grow in size, allowing any function
to modify any piece of data means that bugs can
have wide-reaching effects.
5
What Is Object Oriented (OO)
Programming
Object-oriented (OO)programming is
a programming paradigm that represents
concepts as "objects" that have data
fields (attributes that describe the object) and
associated procedures known as methods.
Objects, which are usually instances of classes,
are used to interact with one another to design
applications and computer programs, software
or systems.
6
A world full of objects
Our world…..
Full of objects
The planet earth
Objects
7
HOW OOP DIFFERS
A collection of software objects constitute an
OO system
Each object encapsulates some data and
some related behaviour
Objects are grouped into classes of similar
objects
Overall system functionality is achieved
through collaborating objects
Collaboration is achieved through the
exchange of messages
Message passing requires corresponding
class or instance methods to be realised. 8
Object-Oriented Software
encapsulated
data
Operation 1
O5
O2 Data messages
O4
O3
operations
Encapsulation +
collaboration of
software objects -
not a UML diagram 9
Basic Concepts
The notion of –
Objects & classes
10
Everyday Objects
We use physical objects all the time.
think of some objects
…in the room,
…things you are carrying
11
Everyday Objects
12
General Features of an Object
Tangible – physical presence
Has some properties
There can be many instances of an object…
We may be able to categorize objects into
different types…
Flying object: birds, aeroplanes, insects ……mention some
others
Living objects: your turn!!!!!……
13
Properties, Values, Types
Think about a “Drinking Glass” object.
List two properties of a glass…
– …and some typical values of each property
Give two examples of different types of “drinking
glass”
14
Property & Values
Properties – fullness Values –
0…..100%
75% 40% 0%
15
Behaviour (actions)
A behaviour is an action associated with an object
The effect of an action may be to:
– change the value of one or more of the object’s
properties
– give some information about its properties
16
Behaviours
Suggest some behaviours of a drinking
glass…….
17
Software objects
A software object is a model of a real or
imaginary object.
We model
Properties and their values with data
variables
Behaviour with functions
In OO jargon these are usually called
Attributes (- the data)
Methods (- the actions) 18
Model Of An Object
A model Definitions:
Definitions from the Oxford English Dictionary
1. “A set of designs (plans, elevations, sections, etc.) for a
projected building or other structure; a similar set of
drawings made to scale and representing the proportions
and arrangement of an existing building.” – anything
wrong?
2. “Something which accurately resembles or represents
something else, esp. on a small scale”
3. “A simplified or idealized description or conception of a
particular system, situation, or process, ... , that is put
forward as a basis for theoretical or empirical
understanding; a conceptual or mental representation of
something.”
19
Examples of Models
• Two different models emphasising
different features
20
How are Models Useful?
Models can show:
– What a finished product will look like
– Structure of main components (how connect
with each other)
– Aspects of behaviour of a product
• Actions it will perform (processes or functions)
• How it will be used
– Suitable materials for building it
– Optimal way of building it
21
Models Depend on Abstraction
Models are developed
– From different perspectives
– To different levels of abstraction
– Hierarchically organised
– In different materials or media
Models give us information (but not too much)
and a perspective to help with a specific task
22
What is Abstraction?
An abstraction:
– represents something else
– logical, rather than physical
– less detailed than what it represents
Hide information that is less relevant to
task
One abstraction = many things
One thing = many abstraction
23
Abstraction in OO Development
Object-Oriented software is heavily based on
abstraction
– All modern programming languages are abstract: code is
far from instructions that actually execute in the CPU
– OO languages further abstract data and behaviour into the
encapsulating concept of objects
– Software design is more abstract still: we specify programs
without coding them
– Analysis is yet more abstract: specify what a system will
do without even knowing the hardware it will run on
– UML provides graphical notations to handle the various
levels of abstraction and detail
24
A Class is a template for
objects
The software model for objects of the
same type is
programmed in a structure called a class.
The class defines
– the attributes (or properties) of the object.
– And the behaviour, by coding the functions
The class also has one or more special
functions
called constructor methods 25
An object is an instance of a
class
When we want to create an object from
the class
template, we invoke the constructor
method.
An instance of the class is created:
– I.e. a set of properties, with initial values.
Each time a constructor is invoked we get
a another new object instance.
When we use the word ‘object’ we 26
method method 28
Self- test
Briefly explain each of the following. Use
examples.
– Class, Object
– Instance, State
– Behaviour, Attribute
– Method, Constructor
– Type, Value
Write some meaningful sentences using
two or
29
more of the above words in each