Foundations of Object-Oriented Analysis and Design - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Foundations of Object-Oriented Analysis and Design

Description:

Learn the principles of good OO class design ... Navigability. 5/5/09. FOOAD: Lecture Six. 11. UML Class Diagram Example. 5/5/09. FOOAD: Lecture Six ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 19
Provided by: codewrang
Category:

less

Transcript and Presenter's Notes

Title: Foundations of Object-Oriented Analysis and Design


1
Foundations of Object-Oriented Analysis and Design
  • Lecture 06 Design Principles Public Interfaces,
    Private Implementations

2
Objectives
  • Learn the principles of good OO class design
  • Learn to use UML Class Diagrams to model the
    classes in a system

3
Elements of UML Class Diagrams
  • Classes
  • Three levels of detail
  • Name only
  • Name and Attributes
  • Name, Attributes and Operations
  • Level of detail depends on how we are using a
    diagram at the time
  • Associations

4
Modeling Classes with UML Class Diagrams
  • Attributes
  • Operations (Methods, Member Functions)
  • Stereotypes

5
Attribute Elements
  • Visibility
  • Name
  • Type
  • Default value (optional)
  • Example
  • private nameString "Bob"

6
Attribute Types
  • Instance attributes
  • Each object of the class has its own attribute
  • Changing the value of the attribute affects only
    the containing object
  • Class attributes
  • Only one instance of the attributes for all
    objects of the class
  • Changing the value of the attribute affects all
    objects of the class

7
Operation Elements
  • Visibility
  • Name
  • Parameter list
  • Return type
  • Example
  • public getName(idInteger)String

8
Operation Types
  • Instance operations
  • Performed only on behalf of an individual object
  • May access and alter instance attributes
  • Class operations
  • Performed on behalf of the class and all
    instances of the class
  • May only access and alter class attributes

9
Common Operations
  • Constructors
  • Executed on creation of an object of the class
  • Usually have several
  • Accessors (queries, getting operations)
  • Return values of attributes
  • Mutators (modifiers, setting operations)
  • Alter the values of attributes
  • Destructors
  • Executed when an object of the class goes out of
    existence
  • Methods Mapped to Class Responsibilities

10
Modeling Associations with UML Class Diagrams
  • Association types
  • Peer-to-peer
  • Aggregation
  • Composition
  • Association elements
  • Multiplicity
  • Roles
  • Constraints
  • Navigability

11
UML Class Diagram Example
12
Aggregation and Composition
13
Public Interface vs. Private Implementation
  • Public interface
  • The totality of a class's public operations
  • The responsibilities of a class are fulfilled by
    its public interface
  • Should be specified such that changes to the
    private implementation don't change the interface
  • Private implementation
  • How the responsibilities are actually performed
  • Should be changeable without affecting the public
    interface

14
Generalization
  • Models the concept of inheritance
  • Subclasses inherit the attributes and operations
    of all their superclasses
  • Objects of a subclass should be substitutable for
    objects of their superclasses
  • Subclasses must conform to the public interface
    of their superclasses

15
Special Class Stereotypes
  • Interfaces
  • Specify public operations, but must not have
    implementation
  • May have attributes but they must be class
    attributes
  • Abstract Classes
  • Specify operations, may or may not have
    implementation
  • May have class or instance attributes

16
Internal Design Principles
  • Preconditions
  • What must be true before a particular operation
    can execute successfully?
  • Postconditions
  • What must be true after sucessful execution of an
    operation?
  • Class invariants
  • What must always be true of the attributes of an
    object of the class

17
Example A Date Class
  • Class invariants
  • Year must be positive number
  • Month must be between 1 and 12 inclusive
  • Day must be between 1 and 31 inclusive
  • Day must be less than or equal to the maximum for
    a given month
  • Leap year anomalies must be correct
  • Preconditions
  • No operation may take a parameter that would
    cause violation of the class invariants
  • Postconditions
  • No operation may leave the object in a state that
    violates the class invariants

18
Deriving Invariants
  • Business rules
  • Data integrity constraints
Write a Comment
User Comments (0)
About PowerShow.com