Object Oriented Analysis OOA Object Oriented Design OOD - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Object Oriented Analysis OOA Object Oriented Design OOD

Description:

A Program is a collection of instructions that can be executed by a computer. ... Exercise Solution. a) Write a program to draw a clown with a red nose and green hair. ... – PowerPoint PPT presentation

Number of Views:769
Avg rating:3.0/5.0
Slides: 23
Provided by: chriswh4
Category:

less

Transcript and Presenter's Notes

Title: Object Oriented Analysis OOA Object Oriented Design OOD


1
Object Oriented Analysis OOAObject Oriented
Design OOD
  • Advanced C
  • Chris Whiteside

2
Software
  • A Program is a collection of instructions that
    can be executed by a computer.
  • Software is one or more programs or portions of
    programs.
  • Programming refers to the act of composing
    software. Synonym Software Development
  • Software Engineering is the disciplined approach
    to software development
  • Two Characteristics of Good Software
  • A correct program is one that properly performs
    the intended task.
  • A readable program is easily understood by other
    programmers.

3
Objects in Software
  • Every object belongs to a group of objects of the
    same type. This group is referred to as the
    objects class..
  • Definition
  • A class defines the state and behavior for some
    group of objects.
  • State is defined via attributes
  • called instance variables in data members.
  • Behavior is defined via operations
  • called methods or member functions

4
What is an Object
  • Definition
  • An object is an entity that has
  • State (what the object looks like) Class Members
    - Attributes
  • Behavior (how the object acts) Class Member
    Functions

Objects Behaviors
Objects State
User
5
Why use OOP ?
  • Encapsulation
  • Inheritance
  • Polymorphism

6
Encapsulation
Objects Behaviors
Objects State
User
Abstraction Data Hiding
7
Inheritance
Objects Behaviors
Objects State
User
Objects Behaviors
Objects State
8
Polymorphism
Objects State
Objects Behaviors
Objects State
User
Objects State
9
Class Diagrams
A class diagram is a picture of the members of a
class. The notation used here is borrowed from
the Universal Modeling Language (UML).
Example
10
Instantiating Objects
  • Objects dont exist until they are instantiated.
    Attempting to call methods on objects before they
    are instantiated is an error.
  • Syntax to Instantiate
  • className variableName
  • Example (assume an object, myTime, of type Time)
  • Time myTime

11
Method Call
The method call is executed, the operation
associated with the method is applied to an
object.
  • Method Call Syntax objectReference.methodName()
  • Where
  • objectReference refers to some particular object,
    and
  • methodName is the name of a parameterless member
    function from the class to which objectReference
    belongs.
  • Examples
  • (assume an object, pen, of type DrawingTool)
  • pen.moveForward()
  • pen.dontDraw()
  • pen.turnClockwise()

12
Statement Sequence
  • Instructions are also called statements.
  • A sequence of statements (instructions) is
    executed in order from top to bottom.
  • Sample
  • (assume an object, pen, of type DrawingTool)
  • pen.draw()
  • pen.moveForward()
  • pen.moveForward()
  • pen.turnClockwise()
  • pen.dontDraw()
  • pen.moveForward()

13
OO Design Strategy
  • The Strategy
  • Identify the objects needed to write the program.
  • Find a class for each object. (Note that some
    classes may need to be written.)
  • Identify the public methods and attributes of
    each new class.
  • Implement the new classes and a driver for the
    program.
  • Hints
  • Objects are often expressed in English in the
    form of a noun or noun phrase.
  • Objects with similar characteristics tend to be
    grouped into a class.
  • During design it is important to remember which
    library classes are at your disposal.

14
Design Principles
  • Use Associations
  • Look for associations among different objects
    that permit grouping them into a single class.
  • Methods should be located within the class they
    are most closely associated.
  • Design with Thin Interfaces
  • The members of a class should be hidden and
    encapsulated whenever possible.
  • Make variables local whenever possible.
  • A variable needs to be an instance variable
    (private) whenever its lifetime must span
    multiple method calls.
  • Instance variables should be private, but public
    methods may grant read and
  • write access when access from outside the class
    is essential.

15
Exercise
  • 1. Consider an object called cruise ship. Which
    of the following would you classify as
    contributing to the state of the cruise ship, and
    which is better associated with its behavior?
  • a) the ship's color
  • b) the act of slowing the ship down to 5 knots
    per hour
  • c) the length of the ship's deck
  • d) turning the ship back toward its home port

16
Exercise Solution
  • a) the ship's color
  • state
  • b) the act of slowing the ship down to 5 knots
    per hour
  • behavior
  • c) the length of the ship's deck
  • state
  • d) turning the ship back toward its home port
  • behavior

17
Exercise
  • 2. For each of the following objects, select a
    class to which this, and other objects, belongs.
  • There exist a wide variety of acceptable
    answers.
  • a) your mother
  • b) Sun Microsystems
  • c) your favorite item of clothing
  • d) the writing utensil you use most often
  • e) your favorite pet

18
Exercise Solution
  • 2. Possible suggestions are shown.
  • a) your mother
  • female
  • b) Sun Microsystems
  • computer manufacturer
  • c) your favorite item of clothing
  • shirt
  • d) the writing utensil you use most often
  • pen
  • e) your favorite pet
  • goldfish

19
Exercise
  • 3. Identify as many objects as you can within
    each of the following requirements statements.
  • a) Write a program to draw a clown with a red
    nose and green hair.
  • b) Write a program to simulate a farm tractor
    pulling a plow through a field.
  • c) Write a program to show three dogs leaping
    though three hoops.

20
Exercise Solution
  • a) Write a program to draw a clown with a red
    nose and green hair.
  • clown, nose, hair
  • b) Write a program to simulate a farm tractor
    pulling a plow through a field.
  • tractor, plow, field
  • c) Write a program to show three dogs leaping
    though three hoops.
  • dog, hoop

21
Exercise
  • 4. For each class diagram below, identify a) the
    name of the class, b) the name of every attribute
    and the class to which the attribute belongs, and
    c) the name of every method.

Time Time() Print() Reset() Hour Minute Second
22
Exercise Solution
  • Class Name
  • Time
  • Attributes
  • Hour
  • Minute
  • Second
  • Methods
  • Time()
  • Print()
  • Reset()
Write a Comment
User Comments (0)
About PowerShow.com