Introduction to ObjectOriented Programming - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Introduction to ObjectOriented Programming

Description:

anything done using O-O can also be done using a procedural paradigm ... widget. Plato's allegory of the cave. Imperial Oil Summer Institute ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 24
Provided by: sandyg
Category:

less

Transcript and Presenter's Notes

Title: Introduction to ObjectOriented Programming


1
Introduction to Object-Oriented Programming
  • Sandy GrahamUniversity of Waterloofor
    theImperial Oil Summer Institutefor Computer
    Studies Teachers
  • August 2003

2
What is O-O?
  • Design, programming, and languages
  • An alternative to procedural programming
  • anything done using O-O can also be done using a
    procedural paradigm
  • Considering a problem from the perspective of
    objects and how they interact

3
Skills for O-O Programming
  • Must have a solid understanding of subprograms
    and parameters
  • stepwise refinement
  • Should understand references/pointers
  • Coding still involves basic concepts
  • selection structures, repetition structures,

4
O-O vs. Procedural
  • Procedural Paradigm
  • Program defines data and then calls subprogram to
    act on the data
  • Object Paradigm
  • Program creates objects that encapsulate the data
    and procedures that operate on the data

5
Basic Concepts
  • Objects
  • Hidden data that is accessed and manipulated
    through a well-defined interface
  • Classes
  • A template or blueprint for creating objects,
    each with their own data
  • Inheritance
  • A new class created by modification of an
    existing class

6
Objects
  • Part of a program which
  • models some real or conceptual object
  • has behavioural responsibilities (behaviours)
  • has informational responsibilities (attributes)
  • Behaviours (methods)
  • things an object can do
  • like procedures and functions in other languages
  • Attributes (fields)
  • information an object knows (has-a)
  • like data and variables in other languages
    (records)

7
Classes
  • A class is a template. No data is allocated until
    an object is created from the class. However
    attributes and behaviours are generically defined
  • The creation (construction) of an object is
    called instantiation. The created object is often
    called an instance (or an instance of class X)

8
Analogies for Classes Objects
  • Class
  • blueprint
  • pattern
  • cookie cutter
  • factory
  • Object
  • building
  • garment
  • cookie
  • widget

Platos allegory of the cave.
9
Class Diagram
Internal/private/helper methods only available
within the class.
Defined by the class. Filled by the object.
10
Encapsulation - Real Life
  • Bank machine
  • Hidden data
  • account balance
  • personal information
  • Interface
  • deposit, withdraw, transfer
  • display account information

11
Classes - Programming
  • Karel the Robot
  • Hidden data
  • location
  • number of Things
  • Interface
  • move, turnLeft
  • pickThing, putThing

12
Multiple Instances of a Class
  • No limit to the number of objects that can be
    created from a class
  • Each object is independent. Changing one object
    doesnt change the others

13
Interaction Among Classes
  • A program is composed of multiple classes
  • Classes may contain references to other classes
    within the set of attributes or behaviours
  • Start in an application class (main)
  • construct one or more objects and call methods
    associated with those objects

14
Using UML in Design
Bank
  • every class has a box
  • class name
  • attributes/instance variables
  • behaviours/methods
  • Arrows indicate the relationships among classes
  • indicates 0-many


1
15
UML for Karel the Robot
16
Documentation for Java
  • Many built in classes available
  • Need at least Java 1.3 to use Karel the Robot
  • http//java.sun.com/j2se/1.3/docs/api/index.html
  • Documentation for Karel the Robot is available in
    the same format
  • http//www.math.uwaterloo.ca/bwbecker/karel/doc/i
    ndex.html

17
Inheritance
  • The inheriting class contains all the attributes
    and behaviours of the class it inherited from
    plus any attributes and behaviours it defines
  • The inheriting class can override the definition
    of existing methods by providing its own
    implementation
  • The code of the inheriting class consists only of
    the changes and additions to the base class

18
Inheritance Diagram
General Outline
19
Why Use Inheritance?
  • Modular coding
  • less code, easier to understand
  • Code reuse
  • dont break what is already working
  • easier updates
  • May not have access to modify the original source
    code
  • Polymorphism

20
Inheritance Terminology
  • Class one above
  • Parent class, Super class
  • Class one below
  • Child class
  • Class one or more above
  • Ancestor class, Base class
  • Class one or more below
  • Descendent class

21
Inheritance Bank Account
22
Inheritance Karel the Robot
  • increase functionality (behaviours)
  • turnRight, turnAround
  • pickAllThings
  • increase attributes
  • starting position
  • number of steps taken

23
Basic Concepts
  • Objects
  • Hidden data that is accessed and manipulated
    through a well-defined interface
  • Classes
  • A template or blueprint for creating objects,
    each with their own data
  • Inheritance
  • A new class created by modification of an
    existing class
Write a Comment
User Comments (0)
About PowerShow.com