Object-Oriented Programming - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Object-Oriented Programming

Description:

Object-Oriented Programming Abstract Data Types (ADTs) Paradigm Evolution Characteristics of OOP Object-oriented Concept Imperative VS OOP Abstract Data Types (ADTs ... – PowerPoint PPT presentation

Number of Views:107
Avg rating:3.0/5.0
Slides: 22
Provided by: Tasan2
Category:

less

Transcript and Presenter's Notes

Title: Object-Oriented Programming


1
Object-Oriented Programming
  • Abstract Data Types (ADTs)
  • Paradigm Evolution
  • Characteristics of OOP
  • Object-oriented Concept
  • Imperative VS OOP

2
Abstract Data Types (ADTs)
  • ????????????????????????????????????????????
    (user defined data type)
  • ??????????? structure ??????????? imperative
  • ??????????????????????????????????????????
    ???????????
  • ??????????????????????????????????????????????????
    ????????????????
  • ??????????????????????????????????? ??????????
    operations ???????????
  • ???????????? ADT ????????????? 2 ????? ???
  • Encapsulation ???????????????? operations
    ?????????????????????????
  • Information hiding ???????????????????????????????
    ??????? operations ?????????????????? ?
  • ???????????? ???? Modula-2, Ada --gt
    object-based

3
Paradigm Evolution
  • Procedural 1950s -1970s (procedural
    abstraction)
  • Data-Oriented early 1980s (data-oriented/ADTs)
  • Object-Oriented late 1980s (Inheritance dynamic
    binding)

Categories of OOP Language
  • ???????? OOP ?????????????????????????????????????
    ???? ???? C, Ada95, CLOS, Scheme
  • ???????? OOP ??????????????????????????????????
    imperative ???? ???? Eiffel, Java
  • ???? OOP ?????????? (Pure OOP) ???? ???? Smalltalk

4
Characteristics of OOP
  • Encapsulation
  • Information hiding
  • Inheritance
  • Dynamic binding

Data
Operation
Data Operation
5
OOP definitions
  • Class
  • Object, instance
  • Subclass, derived class
  • Superclass, parent class
  • Method
  • Message, behavior
  • Inheritance
  • Polymorphism
  • Overriding
  • Encapsulation

6
Object-oriented concept
  • ????? (Object) ????????????????? (state)
    ?????????????????????? ???????????????????????????
    ?? ???? ?????,?????????????,??????????????????????
    ??????
  • ???????? --gt ?????
  • ?????? ???? ??????? ??????????
  • ??????? ???????????? ? ??????????????????,
    ??????????????????
  • ???????????? Imperative ??????????????????????????
    ?????????????????????????

7
Object-oriented concept
  • Class ???????????????????????????????????????????
    ????
  • Instance ?????????????????????????????????????????
    ? class ????
  • ????????????????????????????????????????????
  • ?? method ???????????????????? ?????????????
    instance ????
  • ??????????? instance ??? class ??????? instance
    ?????????????????????????????????
    ???????????????????????
  • ?????????? instance ???? ?????????????? ?
    ?????????????????????
  • Class -gt Type
  • Instance -gt Variable

8
OO Thinking
9
Procedural thinking
  • Procedure draw(diagram d)
  • begin
  • for each shape s in diagram d do
  • begin
  • case s of
  • box code to draw a box
  • ellipse code to draw an ellipse
  • ..

arc code to draw an arc
10
Object-oriented concept
  • Class ???????????????????????? ? ??? object
  • ???????????????????????????? object
    ????????????????? instance ????
  • Object ??????????????????????????????? message
  • ????? object ?????? message ?? execute method
    ????????????
  • Class ???????????????? 2 ?????? ???
  • data member ??????????????????????
    ??????????????? ??????????????????????????
    ????????????????? object
  • method member ????????????????????????
    ?????????????? message ????????? ? ??? method

11
Object-oriented concept
  • ?????????????? class ??????? ????? class
    ??????????????????????????????????????????????????
    ?????????????????????????????????
  • class ???????????????????????????? ????????????
    superclass ??? class ????
  • class ?????????????????? class ???????????????????
    ??????????????????????????????????????????????????
    ???????? ?????????????? subclass ??? class ????
  • ???????????? class ??????????????
    ?????????????????? ???? inheritance

12
OO Thinking
Class Shape methods initialize, draw, offset,
setwidth, setheight, setalign variables
width, height, align
Class Box methods draw, offset
Class Ellipse methods draw, offset
Class Line methods initialize,draw variables
shadow
Class Text methods initialize,draw variables
string
Class Circle methods initialize
13
Object-oriented concept
  • Method overriding ??????????????????? method ??
    subclass ?????????????????? method ?? parent
    class ???????????????????????? method ?? parent
    class ?????????????????? subclass
  • ??? binding ??????? method ??? instance ?????????
    method ????? ??????? dynamic binding
  • ???????????????????? instance ??? class
    ?????????????? method ????????????????
    polymorphism
  • polymorphism ?????????????????????????????????????
    ??????????????? ????????????????????????

14
Object-oriented concept
  • Method overloading ???????????? method ?????????
    argument ???????????????????????????????????
    ??????????????? ? method ??????????????????????
    ???? method ????????????????????? 3 method ??????
    argument ??????? ???
  • function add(xinteger yinteger)
  • function add(xreal yreal)
  • function add(xinteger yreal)
  • Multiple Inheritance ???????????? class ???????
    class ??????????????? class

15
Example in C
  • class A
  • public
  • int x
  • char f( )
  • A( )
  • class D public A
  • int x
  • int g( )
  • class D ???? subclass ??? class A
  • Object ??? class D ???????? 4 ??????
  • x ???? data member ????????? (inherit) ?????
    class A (Ax)
  • f ???? method ?????????????? class A
  • x ???? data member ???????????????? class D
  • g ???? method ???????????????? class D

Encapsulation Inheritance
16
Example in C
  • class Shape
  • public Shape draw (Shape )
  • return this
  • class Ellipse public Shape
  • public Shape draw (Shape )
  • return this
  • class Circle public Shape
  • public Shape draw (Shape )
  • return this
  • Shape s
  • s new Ellipse
  • Shape p ...
  • s-gtdraw(p) // Ellipsedraw(p)
  • s new Circle
  • s-gtdraw(p) // Circledraw(p)

Polymorphism Dynamic binding
17
Example in C
  • class List
  • cell rear
  • public List( )
  • int empty( )
  • protected
  • void add(int)
  • void push(int)
  • int get( )
  • class Queue public List
  • public
  • Queue( )
  • int get( ) return Listget()
  • void put(int x) add(x)
  • ????????? object ?? class Queue
  • Public function
  • Queue added(constructor)
  • get added
  • put added
  • Listempty inherited
  • Protected function
  • add inherited
  • push inherited
  • List get inherited

Information Hiding
18
???????? OOP
  • ?????????? ???????????????????????????????????????
    ????????? ?????????????????????????? object
    ?????????????????????????????????????
  • ?????????? ??????????????????????
  • ???????????????? ?????????????? error ?????
  • ?????????????????? (reusability)
    ??????????????????????????
  • ?????????????????? ?????????? platform

19
?????????? OOP
  • ????????? ?????????????????????????????
    ???????????????????? ??? procedural
  • ??????????????????????????????
  • ??????????????? ??????????? multiple inheritance

20
Imperative VS Object-oriented
  • Imperative
  • Top-down design
  • Procedure-oriented
  • Algorithm
  • Share global data
  • Program-data separation
  • Data transportation
  • Single flow
  • Object-oriented
  • Bottom-up
  • Object-oriented
  • Behavior
  • Information hiding
  • Encapsulation
  • Communication with messages
  • Multiple objects

21
Question
  • ???????????????????
  • ?????????????
  • ???????????????????????????
  • ???????????????????????????????????????????????
  • ????? ??? ??????????????????????????
  • ?????????????
  • ????????????????????????
Write a Comment
User Comments (0)
About PowerShow.com