Chapter 17 ObjectOriented Design - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

Chapter 17 ObjectOriented Design

Description:

Rental items. Database of items. Pile. Others are abstract. Scanner. Streams, ... DVD rental is a rental. King is a chess piece. Aggregation. Has-a relationship ... – PowerPoint PPT presentation

Number of Views:124
Avg rating:3.0/5.0
Slides: 36
Provided by: ameet9
Category:

less

Transcript and Presenter's Notes

Title: Chapter 17 ObjectOriented Design


1
Chapter 17 Object-Oriented Design
2
Chapter Goals
  • To learn about the software life cycle
  • To learn how to discover new classes and methods
  • To understand the use of CRC cards for class
    discovery
  • To be able to identify inheritance, aggregation,
    and dependency relationships between classes
  • To master the use of UML class diagrams to
    describe class relationships
  • To learn how to use object-oriented design to
    build complex programs

3
17.1 Software Life Cycle
  • Software Life Cycle all activities from initial
    analysis until obsolescence
  • Formal process for software development
  • Describes phases of the development process
  • Gives guidelines for how to carry out the phases

4
5 phases
  • Analysis
  • Design
  • Implementation
  • Testing
  • Deployment / Operation

5
5 phases
  • Analysis What is the program supposed to do?
  • Output requirements document
  • Design
  • Implementation
  • Testing
  • Deployment / Operation

6
5 phases
  • Analysis
  • Design How is it going to be implemented?
  • Output Design document (UML/CRC cards/Javadocs)
  • Implementation
  • Testing
  • Deployment / Operation

7
5 phases
  • Analysis
  • Design
  • Implementation Write the code
    (edit/compile/run)
  • Output Completed program
  • Testing
  • Deployment / Operation

8
5 phases
  • Analysis
  • Design
  • Implementation
  • Testing Verify that it works correctly
  • Output Test cases passed (unit/system)
  • Deployment / Operation

9
5 phases
  • Analysis
  • Design
  • Implementation
  • Testing
  • Deployment / Operation Maintain the program
  • Output Public product, patches, new features

10
Perfect World
  • In a perfect world, everything would flow
    perfectly in this process
  • Output from one phase signifies it is complete
    and can start the next phase
  • Doesnt really work
  • Youve probably noticed this
  • Was anyones A5 perfect?
  • Have your tests every worked completely?

11
Waterfall Model
12
Problems with Waterfall Model
  • Specs usually have flaws
  • Contradictions
  • Non-thorough (what needs to happen on bad input?)
  • Design too complicated, implementation flawed
  • Testing incomplete

13
Spiral Model
  • Breaks development process down into multiple
    phases
  • Early phases focus on the construction of
    prototypes
  • Shows some aspects of the final product ? quick
    implementation
  • Lessons learned from development of one prototype
    can be applied to the next iteration
  • Problem can lead to many iterations, and process
    can take too long to complete ? high cost and low
    throughput

14
Spiral
Prototype 1
Prototype 2
Final Product
15
Extreme Programming
  • Approach suggested by Kent Back in 1999
  • Goal Simplicity
  • Cut out formal structure
  • Focus on set of practices to make programming
    more efficient and satisfactory

16
Practices
  • Realistic planning Customers make business
    decisions (what should it look like?),
    programmers make technical ones (how do we that?)
  • Small Releases start small, update later
  • Metaphor common story among programmers
  • Simplicity simple solution is best
  • Testing by everyone!
  • Refactoring restructure as you go

17
Cont.
  • Pair Programming
  • Collective Ownership
  • Continuous Organization
  • 40-hour week
  • On-site customer
  • Coding standards

18
17.2 Discovering Classes
  • Recall that part of the design phase is deciding
    what structures you need to solve a task
  • In OOD this translates into 3 steps
  • Discover classes
  • Determine the responsibilities of each class
  • Describe relationships between each class

19
Class concept
  • Recall that a class represents a concept
  • Some are concrete (i.e. real world)
  • A bank account
  • Rental items
  • Database of items
  • Pile
  • Others are abstract
  • Scanner
  • Streams, Math

20
Simple rule
  • Look for nouns in task description (specs)
  • Obviously not all nouns are classes
  • But can create a list of candidate classes
  • Then determine which ones are useful
  • Cross them off your list

21
Key points
  • Class represents set of objects with the same
    behavior
  • Entities with multiple occurrences in
    problemdescription are good candidates for
    objects
  • Find out what they have in common
  • Design classes to capture commonalities
  • Not all nouns need a new class
  • Address needs to represented, do we need a new
    class or can we use a String?
  • Could have argument for both but must balance
    generality with limiting design

22
Behavior
  • After set of classes have been sketched up,
    define behavior/purpose, of each class
  • Verbs methods

23
CRC Card
  • Describes a class, its responsibilities, and its
    collaborators
  • Use an index card for each class
  • Pick the class that should be responsible for
    each method (verb)
  • Write the responsibility onto the class card
  • Indicate what other classes are needed to fulfill
    responsibility (collaborators)

24
(No Transcript)
25
17.3 Relationships Between Classes
  • Good practice to document relationship between
    classes
  • Can uncover common behavior
  • Divide uncommon classes among programming teams
  • We have learned about inheritance as a
    relationship
  • 4 total important relationships
  • Inheritance is often overused, recognize its
    unique application

26
3 relationships
  • Inheritance
  • Interface Implementation
  • Aggregation
  • Dependency

27
Inheritance
  • Is-a relationship
  • Relationship between a more general class
    (superclass) and a more specialized class
    (subclass)
  • Every
  • savings account is a bank account
  • DVD rental is a rental
  • King is a chess piece

28
Aggregation
  • Has-a relationship
  • Objects of one class contain references to
    objects of another class
  • Use an instance variable
  • Class A aggregates class B if A contains an
    instance field of type B

29
Aggregation vs. Inheritance
  • Two are often confused
  • Example
  • Why not make BankAccount an instance field of
    CheckingAccount?
  • How about extend a Circle for Tire
  • A Tire is not a circle it is a car part
  • But it can be described by a circle

30
Example
  • Car is a Vehicle Inheritance
  • Car has a set of Tires Aggregation
  • class Car extends Vehicle
  • . . .private Tire tires

31
Dependency
  • Dependency occurs when a class uses another class
    methods
  • Uses relationship
  • Example many of our applications depend on the
    Scanner class to read input
  • Aggregation is a stronger form of dependency
  • Obviously uses the class if it is an instance
    field

32
(No Transcript)
33
(No Transcript)
34
AT 17.1
35
Attributes and Methods in UML Diagrams
  • UML has a lot of rules, but you can be as
    specific as necessary for the design
  • Include access specifiers
  • is public
  • - is private
  • Include parameter types and return type
  • Include relationships between classes
Write a Comment
User Comments (0)
About PowerShow.com