Title: Remote OMNeT v2.0 Presentation
1Budapest University of Technology and
EconomicsDepartment of Telecommunications
Object-oriented Programming
2Topics
- Object-oriented programming
- whys
- goals
- history of programming technologies (paradigms)
- Object-oriented point of view
- concept of object
- classes
- Modelling with objects
- static modelling
- relations
- subclassing
- multiple subclassing
- dinamic modelling
- events and states
- communications
3Topics
- Developing with objects
- UML
- identifying objects and classes
- identifyin
4Requirements
5Introduction
- To understand the concept and use of
object-oriented paradigm we need a programming
language to do some examples - this programming language is JAVA
- we only use it as a demo language
- First, look over the history of programming and
programming languages
6History
- In the beginning
- no structure
- mainly in assembly
- no planing
- variables were declared randomly in the code
- no clear control structures
- goto and jump
- common knowledge Do not jump into the middle of
a loop - First high-level languages (FORTRAN, ALGOL)
- no solutions for the previous mentioned problems
- only some genious programmers could understand
the difficult programs - very hard to change
- first software crisis
7History
- Structured programming
- conceptual model Dijkstra
- we need an abstract machine (A) than has only one
instructionSolve the problem - because we dont have such machine, we need
another abstract machine (B) with specified
instruction set (we define it) and with this
machine we make the machine simulating the first,
A machine. - because we dont have the B machine either, we
define an abstract machine (C) with larger
intruction set, and with this C machine we
simulate the B machine -
- finally we have to implement these abstract
machines in the programming language (PASCAL, C,
etc.)
8History
- Example
- Read three numbers that are the coefficients of a
quadratic equation and solve the equation.
A
B
C
read the numbers solve the equation
read the numbers check the coefficients calculate
the discriminant
solve the problem
- abstraction and decomposition
9History
- Modular programming
- hierarchical structure must be compiled together
- program must be decomposed into smaller pieces
that can be compiled separately - cohesion in a modul is stronger and the coupling
among the moduls are weaker
10History
- Abstract data structures
- one data structure one function ? one data more
functions - an abstract data structure is defined by its
operations - example integer
- the abstract data structure is independent of the
implementation
Operation Domain Range NEW () stack PUSH (stack,
element) stack POP (stack) stack TOP (stack) eleme
nt EMPTY (stack) boolean
11Object I.
- Example stack
- use the previously defined stack
- if we have only one instance of the stack we can
define the data structure and the handling
functions in a separate stack.h file - the functions are naturally extern
stack.h stack.c static struct stack ...
extern void new () void new ()extern void
push (struct element x) void push (struct
stack x)extern void pop (struct element
x) void pop (struct stack x)extern void top
(struct element x) void top (struct stack
x)extern bool empty () bool empty (struct
stack x)
12Object II.
- Example stack (cont.)
- the program using data structure stack
include "stack.h" struct element ... a, b,
c...new ()push (b)...top (c)if (empty
()) ...
- Problems with more stacks
- creating more stack modules (static)
- aPush, bPush and aStack, bStack
- the handling functions contain the stack as
paramteter - eg. void push (struct stack s, struct element
x)
13Object III.
- Instatiation
- from the precious example it is clear that we
need many instances from a data structure defined
by operations - like int a, b
- it is partly solved constants, structures
(records)
We need such data structures that can be
instantiated like variables and the operations
are also instantiated with the structure. It
means that the specified operation is defined by
the data structure and they exist together.
14Concept of the Object
The object is an identifiable character of a
system, and this object is characterized by its
behaviour, and inner structure and state.
- The object plays a role in the system. Playing
this role the object shows certain behaviour to
its environment. - Other objects can't look into the specified
object, they can deduce the structure and state
only through the behaviour of the object. As a
result, an observer doesn't know the inner
operation of the object. - The principle is the information hiding and its
applications is encapsulation. - the object encapsulates the data storing its
state and their structure, and the operations can
be performed on this data structure
15Responsibility
- All objects are responsible for themselves
- it means that the object must fulfill the tasks
that are
void print (file) switch (kind_of (file))
case ascii print_ascii (file)
break case msword70 print_msword70 (file)
break case tiff print_tiff (file) break
case bmp print_bmp (file) break ...
void print (file) file.print ()
16Behaviour
- Active
- the object is always working, doing its job while
it starts, stops or effects other objects. - Passive
- the objects does nothing until some environmental
effect (a message) does not force the object to
work
17Messages
- Objects can take effect on each other by sending
messages - in simple cases sending a message is the same as
a function call - Roles of messages
- data exchange
- control
- Message components
- name (for identification)
- parameters
18Methods
- After receiving a message the object does some
action depending on its state and the content of
the message - The object reacts to a message having the name A
with accomplising the method specified by the
same name (A) - The message specifies what the object should do,
the method defines how it must be done. - The object reacts differently to the same message
depending on its state - e.g. borrowed book
19States
- The object stores the previously received
messages, their order and other information that
could be important for the object - this is called the state of the object
- The state is stored in the attributes
- The values of an attribute can change during the
life of the program, so we use variables for
attributes
20Classes and intances
Student
namesexageclassesstate
James Student
Eve Student
take classmarry
21Java classes
public class Student private String
name private int sex private int
age private String lectures private
String state public void takeClass (String
lect) public void finishClass (String lect)
public void takeOffClass (String lect)
public void marry () public void divorce
()
- naming conventions
- public, private, (protected)