Introduction to Object-Oriented Programming (OOP) - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to Object-Oriented Programming (OOP)

Description:

Introduction to Object-Oriented Programming (OOP) History. Machine language. Assembly language ... CGI. Perl, Java script, TCL. Many other domain-specific languages ... – PowerPoint PPT presentation

Number of Views:2167
Avg rating:3.0/5.0
Slides: 15
Provided by: sciBrook
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Object-Oriented Programming (OOP)


1
Introduction to Object-Oriented Programming (OOP)
  • History
  • Machine language
  • Assembly language
  • Sub-routines and loop (Fortran)
  • Procedures and recursion (Algol, Pascal, C)
  • Modules (Modula-2, Ada)
  • Objects (Simula, Smalltalk, C,Java)

2
Why OOP?
  • int stack100
  • int top
  • void init()
  • top -1
  • void push(int val)
  • if (!isFull())
  • stacktop val
  • else error(stack is full)
  • ...
  • What are the problems?
  • Not generic
  • What happens if more stacks are needed?
  • What happens if a stack of a different type is
    needed?
  • Fixed size
  • No effective information hiding mechanism

3
Why OOP?
  • define MAX 100
  • typedef struct
  • int top
  • int valMAX
  • STACK
  • typedef STACK STACK_PTR
  • void init(STACK_PTR sp)
  • void push(STACK_PTR sp, int x)
  • int pop(STACK_PTR sp)
  • int isEmpty(STACK_PTR sp)
  • int isFull(STACK_PTR sp)
  • What are the problems?
  • Still not generic
  • What happens if a stack of another type is
    needed?
  • Fixed size
  • No effective information hiding or data
    protection

4
Abstract Data Types (ADT)
  • ADT (V,O)
  • V a set of values
  • O a set of operators
  • Information hiding
  • Encapsulation
  • Modularity

5
Stack is an ADT
class Stack private LinkedList elms
public Stack() elms new
LinkedList() public void push(Object
x) elms.addFirst(x) public
Object pop() if (isEmpty())
throw new RuntimeException("Stack underflow")
else return elms.removeFirst()
public boolean isEmpty() return
elms.size()0
6
Elements of OOP
  • OOP Programming
  • Provides abstractions of both operations and data
  • Classes
  • A class specifies an abstract data type
  • A class can be defined based on others
    (inheritance)
  • A class defines the variables and behavior common
    to all objects of a certain kind

7
Elements of OOP
  • Objects
  • An object has its own state
  • An objects behavior is determined by its class
  • Methods
  • Operations on objects

8
Elements of OOP
  • Messages
  • Objects perform computation by sending messages
    to each other

message receiver method name
parameters
return value
RECEIVER
SENDER
9
Elements of OOP
  • Receivers
  • Messages differ from traditional procedural calls
    in two very important aspects
  • In a message there is a designated receiver that
    accepts the message
  • The interpretation of the message may be
    different, depending upon the receiver

10
Elements of OOP -- Recursive Design
  • Every object has its own memory, which stores
    other objects

11
Inheritance
super-class
ParkingMeter
subclass or extended class
DigitalParkingMeter
AnalogParkingMeter
12
Elements of OOP--Overriding
  • Subclasses can alter or override information
    inherited from super-classes

Bird
NotFlyingBird
Penguin
13
Why is OOP popular?
  • Hope that it will quickly and easily lead to
    increased productivity and improved reliability
    (solve the software crisis)
  • Hope for easy transition from existing languages
  • Mimic problem solving in real worlds

14
Java is not Cure-all
  • Database
  • Database programming languages
  • Artificial intelligence
  • Lisp, Prolog, Constraint languages
  • CGI
  • Perl, Java script, TCL
  • Many other domain-specific languages
Write a Comment
User Comments (0)
About PowerShow.com