1 Generalizations Multiple Inheritance (finishing up Class Design) Class Design – Another Look – Part 11.

Slides:



Advertisements
Similar presentations
Construction process lasts until coding and testing is completed consists of design and implementation reasons for this phase –analysis model is not sufficiently.
Advertisements

UML (cont.) “The Unified Modeling Language User Guide” by G. Booch, J. Rumbaugh and I. Jacobson ● Classes ● Relationships ● Class diagrams ● Examples.
Object-oriented modeling Class/Object Diagrams
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
Chapter 10: Introduction to Inheritance
UML Class Diagram. UML Class Diagrams2 Agenda What is a Class Diagram? Essential Elements of a UML Class Diagram Tips.
Object-Oriented Analysis and Design
Use-case Modeling.
1 Software Testing and Quality Assurance Lecture 12 - The Testing Perspective (Chapter 2, A Practical Guide to Testing Object-Oriented Software)
1 Generalizations Multiple Inheritance Polymorphism Class Design – Another Look – Part 11.
Object Oriented Analysis and Design Using the UML
1 Software Testing and Quality Assurance Lecture 28 – Testing Class Hierarchies.
What is UML? A modeling language standardized by the OMG (Object Management Group), and widely used in OO analysis and design A modeling language is a.
Copyright 2004 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Second Edition Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Appendix.
Lecture a: Additional UML Models: Package, Activity, Deployment Lecture b: Generalization, Aggregation and Additional Domain Model Notation Copyright W.
Lecture 13: Object- Oriented Concepts Anita S. Malik Adapted from Schach (2004) Chapter 7.
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
PRJ566: PROJECT PLANNING AND MANAGEMENT Class Diagrams.
UML Class Diagrams: Basic Concepts. Objects –The purpose of class modeling is to describe objects. –An object is a concept, abstraction or thing that.
Lawrence ChungCS6359.0T1: Module 41 Module 4: Relationships.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Copyright 2001 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Appendix A Object-Oriented.
Object Oriented Analysis & Design & UML (Unified Modeling Language)1 Part V: Design The Design Workflow Design Classes Refining Analysis Relationships.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 4th Edition Copyright © 2012 John Wiley & Sons, Inc. All rights.
UML Diagrams: Class Diagrams The Static Analysis Model Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
R McFadyen Chapter 7 Conceptual Data Modeling.
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 10 Use Case Design.
Systems Analysis and Design in a Changing World, 6th Edition 1 Chapter 4 - Domain Classes.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Slide 1 Structural Modeling Chapter 7. Slide 2 Key Ideas A structural or conceptual model describes the structure of the data that supports the business.
Object oriented classification Classification is the process of checking to see if an object belongs to a category or a class, is regarded as a basic attribute.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
CS3773 Software Engineering Lecture 04 UML Class Diagram.
7-1 © Prentice Hall, 2004 Chapter 7: Conceptual Data Modeling Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
Class Diagrams Identifying and representing Classes Object Web, Bapayya Choudhary Maganti.
Unified Modeling Language © 2002 by Dietrich and Urban1 ADVANCED DATABASE CONCEPTS Unified Modeling Language Susan D. Urban and Suzanne W. Dietrich Department.
® IBM Software Group © 2006 IBM Corporation Rational Software France Object-Oriented Analysis and Design with UML2 and Rational Software Modeler 03. Classes,
Chapter 8 Analysis & Modeling. Data Modeling examines data objects independently of processing focuses attention on the data domain creates a model at.
UML Class Diagram Trisha Cummings. What we will be covering What is a Class Diagram? Essential Elements of a UML Class Diagram UML Packages Logical Distribution.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Object Oriented Analysis & Design Using UML (CS-512) M-Tech CSE (Ist & 3rd Sem) Part Time Mr. Pawan Luthra Assistant Professor (CSE Deptt.) SBSSTC, Ferozepur.
What is a Structural Model?
Class Diagram. Classes Software Design (UML) Class Name attributes operations A class is a description of a set of objects that share the same attributes,
Design Model Lecture p6 T120B pavasario sem.
Object Oriented Analysis: Associations. 2 Object Oriented Modeling BUAD/American University Class Relationships u Classes have relationships between each.
 Week08.  Review Schedule Weeks 8-14  This week o Review last class o Introduce Class Diagrams o ICE-03 Sheridan SYST Engineering Quality Systems.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Object-Oriented Analysis and Design CHAPTERS 9, 31: DOMAIN MODELS 1.
OOAD Using the UML - Introduction to Object Orientation, v 4.2 Copyright  Rational Software, all rights reserved 1 Object Oriented Analysis.
Chapter 17 – Object- Oriented Design. Chapter Goals To learn about the software life cycle To learn about the software life cycle To learn how to discover.
Class Diagram Chapter 21 Applying UML and Patterns Craig Larman.
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall Object-Oriented Systems Analysis and Design Using UML Systems Analysis and Design,
Analysis Yaodong Bi. Introduction to Analysis Purposes of Analysis – Resolve issues related to interference, concurrency, and conflicts among use cases.
ITEC0724 Modern Related Technology on Mobile Devices Lecture Notes #2 1.
1 SWE Introduction to Software Engineering Lecture 14 – System Modeling.
OOAD Using the UML - Use-Case Analysis, v 4.2 Copyright  Rational Software, all rights reserved 1 Use Case Analysis – Part 4 Analysis Mechanisms.
UML Diagrams: Class Diagrams The Static Analysis Model
Chapter 5: Structural Modeling
Class Diagrams.
Interface, Subclass, and Abstract Class Review
Class diagram Description
Chapter 8 Analysis & Modeling
UML Class Diagrams: Basic Concepts
Object Oriented Analysis and Design
Domain Class Diagram Chapter 4 Part 2 pp
Object Oriented Analysis and Design Using the UML
Object Oriented System Design Class Diagrams
Presentation transcript:

1 Generalizations Multiple Inheritance (finishing up Class Design) Class Design – Another Look – Part 11

2 Class Design Steps  Create Initial Design Classes  Identify Persistent Classes  …  Define Dependencies  Define Associations  Define Generalizations In analysis, inheritance inherent to the problem domain may have been defined. Class Design is where generalizations are defined to improve/ease the implementation. Design is the real activity of inventing inheritance.  Checkpoints

3 Generalization  Is a notational convenience allows us to define common structure and behavior in one place and re-use it where we find repeated behavior and structure.  Discuss: What does ‘structure’ mean to you?  Discuss: What does ‘behavior’ mean to you?  Makes ‘change’ and ‘maintenance’ easier: Generalization extracts common properties into classes of their own

4 Define Generalizations  Purpose Identify areas of reuse Refine existing inheritance hierarchies so that they can be implemented efficiently  Things to look for: Abstract classes vs. concrete classes Multiple inheritance problems Generalization vs. Aggregation Generalization to support implementation reuse

5 Review: Generalization  Is a ‘relationship where one class shares the structure and/or behavior of one or more classes  “Is-a-kind of” relationship  Should always be able to say that your derived / child class ‘is a kind of’ parent class  Can us terms ‘ancestor’ and ‘descendent’ instead of super-class and subclass.  In analysis, generalization is used sparingly to model shared behavioral semantics only. (generalization must pass ‘is a’ test).  Generalization cited in  analysis is used to support reuse in Design. Account balance name number Withdraw() CreateStatement() Checking Savings GetInterest() Superclass (parent) Subclasses Generalization Relationship descendents ancestor

6 Generalization in Analysis and in Design  In Analysis, the generalization should be used to reflect shared definitions/semantics and promote “brevity of expression”  (The use of generalization makes the definitions of the abstractions easier to document and understand).  Think boundary classes for interfacing….  May be used in the Domain Model (Business Object Model)  A common super-class is created when generalization is found.  Super class contains common attributes, associations and aggregations, and behaviors.  Subclasses have unique, individual attributes/behaviors not common to all subclasses of a super class.  We can draw a generalization relationship from the sub-class to the super-class as we saw in the preceding slide. (solid line, open triangle)

7 Lion talk () Tiger talk () Animal {abstract} talk () {abstract} There can be no direct instances of Animal All objects are either lions or tigers Abstract class Abstract operation Communication Discriminator Abstract and Concrete Classes  Abstract classes cannot have any objects Exist only for other classes to inherit from it  Concrete classes are used to instantiate objects An operation can also be tagged as abstract in UML. Meaning: no implementation exists for the operation in the class where it is specified. (A class that contains at least one abstract operation must be an abstract class.) A discriminator can be used to indicate on what basis the generalization or the specialization occurred.

8 AirplaneHelicopterWolfHorse FlyingThingAnimal Bird multiple inheritance Use multiple inheritance only when needed, and always with caution ! Multiple Inheritance Inheriting from more than one class.  Bird inherits from Flying Thing and Animal  Conceptually simple; necessary for modeling real world accurately. Potential implementation problems.  Not all languages support it. We don’t care in design!! Why?  May need adjustment in design and implementation.

9 Name clashes on inherited attributes or operations Repeated inheritance FlyingThing color getColor Animal color getColor Bird FlyingThing Animal Bird AnimateObject color Multiple Inheritance Problems in Design and Implementation. Resolution of these problems is implementation-dependent In general, multiple inheritance causes problems if any of the multiple parents has structure or behavior that overlaps (see above). If a class inherits from several classes, you must check how relationships, operations, and attributes are named in the ancestors.

10 Window WindowWithScrollbar Scrollbar Is this a correct use of generalization? If not, what would be a better way to model the info which maintains generalization “is-a” semantics? Generalization vs. Aggregation  Generalization and aggregation - often confused Generalization represents an “is-a” or “kind-of” relationship; one object. Aggregation represents a “part-of” relationship  Relates multiple objects;

11 Scrollbar Window WindowWithScrollbar 11 Window WindowWithScrollbar Scrollbar Consider: Which of these is/are true? A WindowWithScrollbar “is a” Window A WindowWithScrollbar “contains a” Scrollbar Or A WindowWithScrollbar “has a” Scrollbar Generalization vs. Aggregation Notice: specialization and the aggregation

12 Generalization Uses Share Common Properties and Behaviors This is the first use of generalization that we have been talking about to this point.

13 List insertTop (Item) insertBottom (Item) removeTop () removeBottom () insert (Item, position) Stack Animal talk () LionTiger talk () Generalization: Share Common Properties and Behavior  Follows the is-a style of programming  Class substitutability A subtype is a type of relationship expressed with inheritance. A subtype specifies that the descendent is a type of the ancestor and must follow the rules of the is-a style of programming. ???

14 List insertTop (Item) insertBottom (Item) removeTop () removeBottom () insert (Item, position) Stack Animal talk () LionTiger talk ()  Do these classes follow the ‘is-a’ style of programming? Generalization: Share Common Properties and Behavior  The “is-a style of programming” states the descendent ‘is-a’ type of the ancestor and can fill in for all its ancestors in any situation. True? Converse?

15 Animal talk () LionTiger talk () Generalization: Share Common Properties and Behavior (contd) List insertTop (Item) insertBottom (Item) removeTop () removeBottom () insert (Item, position) Stack The classes on the left-hand side of the diagram do follow the is-a style of programming: A Lion is-an Animal and a Tiger is-an animal. The classes on the right-hand side of the diagram do NOT follow the is-a style of programming: a Stack is not a List. A Stack needs some of the behavior of a List but not all of the behavior. If a method expects a List, then the operation insert(position) should be successful. If the method is passed a Stack, then the insert(position) will fail.

16 Generalization Uses 1. Share Common Properties and Behavior 2. Share Implementation This use of generalization is where there are some services or structure provided by a class you want to leverage in the implementation of another class. Several different ‘kinds’ of sharing implementations!  Side note: What is wrong grammatically with the sentence starred?

17 List insertBottom (Item) removeBottom () insert (Item, position) Stack SequentialContainer insertTop (Item) removeTop () List insertTop (Item) insertBottom (Item) removeTop () removeBottom () insert (Item, position) Stack Generalization: Share Implementation-Factoring  Factoring is useful if there are some services provided by one class that you want to leverage in the implementation of another class.  When you factor, extract the functionality you want to reuse and inherit it from the new base class.  Supports the reuse of the implementation of another class  Cannot be used if class you want to “reuse” cannot be changed Can see we inherit insertTop() and removeTop() from SequentialContainer; Add those additional behaviors unique to List

18 Checkpoints: Classes (look these over)  Does the name of each class clearly reflect the role it plays? The class should only define attributes, responsibilities or operations that are functionally coupled to the other attributes, responsibilities, or operations defined by that class.  Does the class represent a single well-defined abstraction?  Are all attributes and responsibilities functionally coupled?  Are there any class attributes, operations or relationships that should be generalized, that is, moved to an ancestor? Why?  Are all specific requirements on the class addressed?  Are the demands on the class consistent with any state-charts which model the behavior of the class and its instances?  Is the complete life cycle of an instance of the class described?  Does the class offer the required behavior? If not, why have it??  If the class does not represent a well-defined abstraction, you should consider splitting it.  The complete lifecycle of an instance of the class should be described.  Each object should be created, used, and removed by one or more use-case realizations.  The classes should offer the behavior the use-case realizations and other classes require.

19 Checkpoints: Operations  Are the operations understandable?  Is the state description of the class and its objects' behavior correct? Names of operations should be descriptive and the operations should be understandable to those who want to use them.  Does the class offer the behavior required of it?  Have you defined the parameters correctly (call by reference, call by value, others….) Ensure there are not too many parameters for an operation.  Are the implementation specifications (if any) for an operation correct? (Got those from??)  Do the operation signatures conform to the standards of the target programming language?

20 Checkpoints: Attributes  Does each attribute represent a single conceptual thing (noun, noun clause)?  Are the names of the attributes descriptive?  Are all the attributes needed by the use-case realizations? (Remove any attributes that are redundant and not needed by the use-case realizations.) Remember, any thing you have may cause problems later in quality control, testing, configuration management, versioning, future maintenance, ….  Be sure to identify and define any applicable default attribute values.

21 Checkpoints: Relationships  Are the role names descriptive? Define roles?? Remember?  Are the multiplicities of the relationships correct?  The role names of the aggregations and associations should describe the relationship between the associated class to the relating class.

22 Review: Class Design  What is the purpose of Class Design?  In what ways are classes refined?  What is the difference between an association and a dependency?  What is done with operations and attributes ?