INTRODUCTION TO OO DESIGN - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

INTRODUCTION TO OO DESIGN

Description:

Chapter 1 of M. Page-Jones(2000) Fundamentals of Object-Oriented ... Set of UML diagrams and program ... Bastard classes. SOME MORE DESIGN PROBLEMS ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 27
Provided by: davidjbarn6
Category:

less

Transcript and Presenter's Notes

Title: INTRODUCTION TO OO DESIGN


1
INTRODUCTION TO OO DESIGN
2
INTRODUCTION TO OO DESIGN
  • Why design?
  • Characteristics of good design
  • Object Oriented Design
  • Reading
  • Chapter 1 of M. Page-Jones(2000) Fundamentals of
    Object-Oriented Design in UML.
  • Chapters 1 and 2 of P. Stevens (2000) Using UML
    Software engineering with objects and components.

3
OO DESIGN AND SOFTWARE DEVELOPMENT
  • In waterfall before implementation
  • Set of UML diagrams and program stubs as output
  • In Agile there is also a design phase but
    frequently merged with coding

4
WHY DESIGN?
  • Complex Systems
  • Large systems (too complex for one person)
  • Hard constraints (costs, time, space)
  • Maintenance
  • Changing requirements
  • Need to re-use
  • Invisibility. Unlike other artefacts software is
    dynamic and abstract

5
WHAT ARE GOOD SYSTEMS LIKE?
  • Systems that are
  • Easy to modify
  • Easy to understand
  • Re-usable
  • Pluggability
  • Customisable
  • Comprised of modules
  • Relatively independent (low coupling)
  • Well defined interface (encapsulated)
  • Well defined and understood entities
    (abstraction)
  • High cohesion

6
OBJECT-ORIENTED DESIGN
  • Current best shot at producing good systems
  • Previously
  • Systems looked at in terms of processes and
    information manipulated by those processes
  • In OO
  • Systems looked at in terms of objects (cohesive
    entities comprising processes and information)
    and their interrelations

7
WHAT DOES OO MEAN?
  • Discuss what are the main characteristics of OO.
  • Compile a list of around 7 main characteristics.

8
THE POLYGONS PROGRAM
9
TRIANGLE CLASS
  • Triangle
  • Creates and returns a new instance of a triangle
  • makeVisible
  • Turns the triangle visible on the canvas
  • changeColor
  • Changes the color of the triangle
  • changeSize
  • Changes the size of the triangle
  • moveUp
  • Moves the triangle up one unit
  • moveDown
  • Moves the triangle down one unit
  • moveVertical
  • Moves the triangle vertically by a specific
    amount
  • getArea
  • Obtains the value of the triangles area

10
CANVAS CLASS
  • Canvas
  • Creates and returns a new instance of a canvas
  • add
  • Adds a triangle to the canvas
  • delete
  • Deletes a triangle from the canvas
  • setDimension
  • Sets the dimension of the canvas
  • getDimension
  • Obtains the dimension of the canvas
  • setGridUnit
  • Sets the number of pixels per grid unit
  • getGridUnit
  • Obtains the number of pixels per grid unit

11
ENCAPSULATION
Operations
changeSize
Packaging of operations and attributes into an
object type so state is accessible only via the
provided interface
changeColor
moveUp
moveDown
getArea
Variables
12
IMPLEMENTATION HIDING
  • Use of encapsulation to restrict visibility of
    implementation decisions internal to the objects
    structure
  • Are triangle objects represented as three point
    coordinates?
  • How do we make a triangle visible?
  • How are the added triangles represented within a
    canvas object? As a list? As independent objects?

13
STATE RETENTION AND OBJECT IDENTY
Triangle1 new Triangle
Triangle2 new Triangle
Triangle1
Triangle2
14
STATE RETENTION AND OBJECT IDENTY
Triangle1 Triangle2
Triangle1
Triangle2
15
MESSAGES
triangle1.changeColor(red)
target object
Argument(s)
operation name
message
  • Accessors
  • Mutators

16
THE POLYGONS PROGRAM
17
INHERITANCE
Polygon
18
POLYGON CLASS
  • Polygon
  • Creates and returns a new instance of a polygon
  • makeVisible
  • Turns the polygon visible on the canvas
  • changeColor
  • Changes the color of the polygon
  • changeSize
  • Changes the size of the polygon
  • moveUp
  • Moves the polygon up one unit
  • moveDown
  • Moves the polygon down one unit
  • moveVertical
  • Moves the polygon vertically by a specific amount
  • getArea
  • Obtains the value of the polygons area

19
TRIANGLE CLASS
  • Triangle
  • Creates and returns a new instance of a triangle
  • getArea
  • Obtains the value of the triangles area

20
POLYMORPHISM
  • Variable polymorphism
  • Polygon myPolygon
  • myPolygon new Triangle
  • Method polymorphism
  • getArea is defined in Polygon and all its
    subclasses
  • Each of the subclasses overrides this method

21
POLYMORPHISM AND OVERRIDING
22
PROTECTED ACCESS
  • Private access in the superclass may be too
    restrictive for a subclass.
  • The closer inheritance relationship is supported
    by protected access.
  • Protected access is more restricted than public
    access.
  • Keeping fields private still recommended.
  • Define protected accessors and mutators.

23
ACCESS LEVELS
24
SOME DESIGN PROBLEMS (CODE SMELLS)
  • Overworked Method
  • Method calculates and prints result
  • Schizoid Class (represents more than one entity)
  • Only one class for the GUI
  • Method in exile
  • Store calculating total of shopping basket
  • Lazy class
  • Message class that only displays a message
  • Bastard classes

25
SOME MORE DESIGN PROBLEMS
  • Speculative generality
  • System implements design pattern in case some
    sophisticated functionality is required in the
    future
  • Middle man
  • StoreText just passes requests to Store
  • Frequent switch statements
  • Different types of products
  • Agent as class
  • Customer class with selectService, requestBooking
    methods
  • Inappropriate intimacy
  • CustomerDB providing classes such as getXMLFile

26
SUMMARY
  • Good design produces software which is
  • Easy to understand
  • Easy to modify
  • Re-usable
  • Good design has
  • Modularity
  • Low coupling
  • High cohesion
  • Important OO concepts
  • Encapsulation, Implementation hiding, state
    retention, object identity, messages,
    inheritance, polymorphism
Write a Comment
User Comments (0)
About PowerShow.com