Introduction to Object-Oriented Programming - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Introduction to Object-Oriented Programming

Description:

Class Diagram. Fields. of. the. Class. Interface. method. method. method. method. method. method. method ... classes within the set of attributes or behaviours ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 20
Provided by: sand233
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Object-Oriented 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
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

12
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

13
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
14
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

15
Inheritance Diagram
General Outline
16
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

17
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

18
Inheritance Bank Account
19
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