Download presentation
Presentation is loading. Please wait.
Published byMyron Rogers Modified over 10 years ago
1
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 1 Systems Analysis and Design Alan Dennis, Barbara Wixom, and David Tegarden John Wiley & Sons, Inc. Slides by Fred Niederman
2
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 2 Copyright © 2001 John Wiley & Sons, Inc. All rights reserved. Reproduction or translation of this work beyond that permitted in Section 117 of the 1976 United States Copyright Act without the express written permission of the copyright owner is unlawful. Request for further information should be addressed to the Permissions Department, John Wiley & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for redistribution or resale. The Publisher assumes no responsibility for errors, omissions, or damages, caused by the use of these programs or from the use of the information contained herein.
3
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 3 Class and Method Design Chapter 14
4
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 4 Key Concepts Low-level or detailed design is critical despite libraries and components Pre-existing classes need to be understood and organized Some, if not all code, is generally still needed to instantiate new classes
5
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 5 Identify Opportunities for Reuse Patterns Useful group of collaborating classes the provide a solution to a commonly occurring problem Framework Classes used for application implementation Class libraries Set of implemented classes designed for reuse Components Self-contained encapsulated pieces of code that provide a certain functionality
6
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 6 REVISITING THE BASIC CHARACTERISTICS OF OBJECT-ORIENTATION
7
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 7 Elements Classes Objects – instance of a class Attributes – describes data States – describes object at specific point in time via an attribute Methods – processes to be performed Messages – used to get an object to perform a method
8
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 8 Encapsulation Hiding the content of the object from outside view Communication only through object’s methods (via messages) Key to reusability
9
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 9 Example Unencapsulated
10
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 10 Example Encapsulated Room contains the knowledge of when it needs heat
11
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 11 Polymorphism Same message triggers different methods in different objects Dynamic binding means specific method is selected at run time Implementation of dynamic binding is language specific
12
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 12 What does it mean? polymorphism refers to a programming language's ability to process objects differently depending on their data type or class programming language'sdata type class it is the ability to redefine methods for derived classes
13
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 13 Example Given a base class shape, polymorphism enables the programmer to define different circumference methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the circumference method to it will return the correct results
14
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 14 More examples Good example Send message ‘print document’ to laser printer or inkjet printer The printer performs its own print operation Bad example Send message ‘create order’ Start the sales process or straighten up the living room?
15
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 15 Polymorphism Challenges Need to be very careful about run time errors Send message to an object that doesn’t understand it Make a decision for which there is no code Need to ensure semantic consistency Same name for a method in 2 classes – does it mean the same thing?
16
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 16 Inheritance Single inheritance -- one parent class Multiple inheritance -- multiple parent classes Redefinition and inheritance conflict Attribute/method with same name Most inheritance conflicts are due to poor classification
17
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 17 Additional Inheritance Conflicts Two inherited attributes or methods have same name and semantics Two inherited attributes or methods have different name, but same semantics Two inherited attributes or methods have same name and different semantics
18
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 18 DESIGN CRITERIA
19
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 19 Good Design – Bad Design Good design balances trade-offs to minimize total cost of a system over its lifetime (Coad and Yourdon) Criteria for assessing good design: Coupling Cohesion Connascence
20
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 20 Coupling Interdependency among modules More interdependency the more likely changes in one part will require changes in others
21
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 21 Two Types of Coupling Interaction coupling through message passing Minimize number of objects that can receive messages Inheritance coupling of superclass and sub classes Tighter coupling is preferred – supports a-kind-of
22
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 22 Law of Demeter – Interaction Coupling Messages should be sent only by an object to itself to an object contained in an attribute of itself or a superclass to an object that is passed as a parameter to the method to an object that is created by the method to an object that is stored in a global variable
23
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 23 Types of Interactive Coupling LevelType GoodNo Direct Coupling – no calls Data – passes variable uses all Stamp – passes object uses some Control – passes control variable Common or Global – outside object BadContent or Pathological – method of one object refers to inside method of another (often illegal)
24
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 24 Good Interaction Coupling Pass value of a variable along with the message Object invoice could send to calculate tax the taxable amount
25
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 25 Bad Coupling Global data area exists outside the object Table of user preferences – global data Can be changed by a number of objects Ie values might be changed between the end of one ‘run’ and the beginning of the next ‘run’
26
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 26 Bad Coupling continued Sales tax percent stored in separate table Calculate sales tax at 6% for one item Another object changes Sales tax percent Next items is calculated with 7% sales tax
27
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 27 Cohesion “Single-mindedness of a module” Object should just represent one thing – a method should solve only one task Types of cohesion: Method cohesion Class cohesion Generalization/specialization cohesion
28
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 28 Types of Method Cohesion LevelType GoodFunctional –single function Sequential –2 functions – output from one is input to other Communicational – 2 functions that use the same attributes Procedural – multiple functions Temporal or Classical – multiple related functions in time Logical – multiple functions with choice by control variable BadCoincidental – purpose not well defined
29
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 29 Method Cohesion Example Good Method Cohesion Object ‘calculate totals’ by keeping a running total Bad Method Cohesion Unrelated activities in the same method Method that updates customer records, calculates loan payments,prints exception reports…
30
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 30 Types of Class Cohesion LevelType GoodIdeal Mixed-role Mixed-domain WorseMixed-instance
31
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 31 Class Cohesion Ideal Methods and attributes all relate to the same entity (employee, student, etc.) Mixed-Role One or more attributes relate to other objects on same layer Student class contains instance of courses student is taking
32
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 32 Class Cohesion Mixed-domain One or more attributes relating to objects on a different layer Data layer refers to objects on presentation layer Mixed-instance Class represents 2 different types of objects Student and class enrollment (should be 2 separate classes)
33
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 33 Connascence Generalizes the ideas of cohesion and coupling Two modules (classes or methods) so intertwined that a change in one will likely require a change in the other
34
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 34 Types of Connascence Type Name Type or Class Convention Algorithm Position
35
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 35 Name Connascence Refers to the situation where a method references an attribute “get product number” refers to attribute in ‘product’ class If ‘product class’ changes the attribute name, the method must change
36
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 36 Type or Class Connascence Refers to relationship between attribute and data type For instance, if date is chosen as the data type and that is changed, class must be changed
37
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 37 Convention Connascence Values of attributes are assigned semantic meaning Ie used as a code Should the range of acceptable values of attribute change, methods must also be changed
38
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 38 Position Connascence Refers to the order of code in the method or the order of arguments Record must be found before being modified Subtle differences can arise Creating averages from subtotals versus the entire data set
39
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 39 Algorithm Connascence Refers to dependency on an algorithm If algorithm changes, methods must change Change a hashing algorithm for finding records Insert record and find record must be changed
40
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 40 Class Constraints A set of constraints and guarantees Written in natural language, structured English, pseudocode, or formal language – can be modeled in UML with OCL (Object Constraint Language)
41
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 41 Define constraints Pre-conditions Must be met for method to execute (ie invalid attributes) Post conditions Must be met after the method is executed (no invalid attributes) Invariants Must be true for all instances of a class (valid values of an attribute)
42
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 42 Constraints - Tomorrow Preconditions Valid value for today’s date Invariants Day, month, year positive numbers Month must be between 1 and 12 Day must be between 1 and 31 Leap year anomalies must be correct Postconditions Valid date for tomorrow
43
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 43 Constraint OCL Example Date :: Tomorrow() pre: year < 9999 or (year = 9999 and month < 12) or (year = 9999 and month = 12 and day <31) post: if day@pre < 31 then day = day@pre + 1 else if month@pre < 12 then month = month@pre + 1 day = 1 else year = year@pre + 1 month = 1 day = 1 end if end if
44
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 44 Contract Documents message passes that takes place between objects Can be written for: Each message sent Each message received
45
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 45 Contract Continued Declarative So programmer understands what the method is to do Not procedural Don’t spell out how the method is to work
46
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 46 Simple Contract Format Method Name: Class Name:ID: Clients (Consumers): Associated Use Cases: Description of Responsibilities: Arguments Received: Type of Value Returned: Pre-Conditions: Post-Conditions:
47
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 47 What to Remember Class Encapsulation Polymorphism Inheritance Coupling Cohesion Connascence What is a good candidate for reuse
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.