3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)

Slides:



Advertisements
Similar presentations
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Advertisements

CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Session 07: C# OOP 4 Review of: Inheritance and Polymorphism. Static and dynamic type of an object. Abstract Classes. Interfaces. FEN AK - IT:
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Object-Oriented.
UMLにおける実体指向. Object-oriented concepts have been around since the 1970s. A variety of programming languages, including C++, Smalltalk, Java, and Eiffel,
Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering.
Copyright W. Howden1 Lecture 6: Design Evaluation and Intro to OO Design Patterns.
Object Oriented System Development with VB .NET
Chapter 14 (Web): Object-Oriented Data Modeling
Criteria for good design. aim to appreciate the proper and improper uses of inheritance and appreciate the concepts of coupling and cohesion.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Design Patterns: someone has already.
Object-oriented design CS 345 September 20,2002. Unavoidable Complexity Many software systems are very complex: –Many developers –Ongoing lifespan –Large.
3/15/05H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
Chapter 14: Object-Oriented Data Modeling
CS 4240: The OO Paradigm Revisited Readings: Chap. 1 of Design Patterns Explained OO (some review) Coupling, cohesion.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
Chapter 25 More Design Patterns.
Design Patterns.
CSCI-383 Object-Oriented Programming & Design Lecture 9.
CS 4240: Bridge and Abstract Factory Readings:  Chap. 10 and 11 Readings:  Chap. 10 and 11.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Database Management System Prepared by Dr. Ahmed El-Ragal Reviewed & Presented By Mr. Mahmoud Rafeek Alfarra College Of Science & Technology Khan younis.
CSC 211 Introduction to Design Patterns. Intro to the course Syllabus About the textbook – Read the introduction and Chapter 1 Good attendance is the.
CS2110: SW Development Methods Inheritance in OO and in Java Part 1: Introduction Readings: A few pages in Ch. 2 of MSD text introduce this Section 3.3.
Association Class Generalization/Specialization Whole-Part Page More Associations 1.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Object Orientation Yaodong Bi, Ph.D. Department of Computer Sciences University of Scranton October 18, 2015October 18, 2015October 18, 2015.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
CHAPTER 13 (ONLINE): OBJECT-ORIENTED DATA MODELING © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition.
7-1 © Prentice Hall, 2007 Chapter 7: Conceptual Data Modeling Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 15: Object-Oriented Data Modeling Modern Database Management 9 h Edition Jeffrey A.
Unit 3 Conceptual Data Modeling. Key Concepts Conceptual data modeling process Classes and objects Attributes Identifiers, candidate keys, and primary.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 13 (Online): Object-Oriented Data Modeling Modern Database Management 10 th Edition.
CHAPTER 13: OBJECT-ORIENTED DATA MODELING (OVERVIEW) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
PROG Object Oriented Programming II With Java PROG Object Oriented Programming II With Java Class Relationships.
What is a Structural Model?
Structural Design Patterns
Object Oriented Software Development
Object-Oriented Data Modeling
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
CS2110: SW Development Methods Inheritance in OO and in Java Part 2: Topics: Forms of inheritance Interfaces in Java.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Object-Oriented Analysis and Design CHAPTERS 9, 31: DOMAIN MODELS 1.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Object-Oriented Programming Chapter Chapter
Object Oriented Programming
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
CS 4240: Rethinking Some OOP Ideas and Terms for OOA&D Readings: Chap. 8 in Shalloway and Trott (referred to as S&T in these slides) Wikipedia on information.
Evaluating an Object-Oriented Design ©SoftMoore ConsultingSlide 1.
Inheritance Type/Subtype Relationship. Inheritance Idea: An object B of one type, termed child class, inherits from another object A of another type,
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
Object Modeling THETOPPERSWAY.COM. Object Modelling Technique(OMT)  Building a model of an application domain and then adding implementation.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 5th Edition Copyright © 2015 John Wiley & Sons, Inc. All rights.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
CSCE 240 – Intro to Software Engineering Lecture 3.
ISBN Chapter 12 Support for Object-Oriented Programming.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Structural Patterns: Adapter and Bridge
Presentation transcript:

3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout) Generalization and specialization Generalization vs. aggregation Other aggregation issues

3/1/01H-2 Cohesion How diverse are the things inside an “entity” –A what? Module, function,… In OO a class. What’s this mean? –Class should represent a single abstraction –Or, it should address a single general responsibility

3/1/01H-3 Problems Created by Bad Cohesion Hard to understand the class If two abstractions grouped into one class, that implies a one-to-one relationship –What if this changes? Often we specialize a class along a dimension –This new thing is like the existing one except we extend it in one area (dimension) –Problems arise when each of the several abstractions need such specialization

3/1/01H-4 The “Multiplicity” Problem Consider an Account class that holds: –Customer name, address, tax ID, Account status, etc. What if one customer needs two accounts? –Two Account objects, but each stores name and address What if one account has two owners? –You can’t do this, unless you create a collection in each Account to hold owner info

3/1/01H-5 Specializing along Dimensions Let’s say we need variations on class Account –First, based on account type: Cash Account, Credit Account –Second, based on customer type: Individual Account, Institutional Account These are two dimensions, but are they mutually exclusive? –We often compose along two dimensions –E.g. Individual Cash Account, Individual Credit Account, etc. Specialization often implemented as inheritance: Do we want multiple inheritance?

3/1/01H-6 Inheritance Diamonds Structures like this cause messy problems!

3/1/01H-7 Separating Abstractions Composition across dimensions achieved by aggregation You can see how this improves earlier problem too

3/1/01H-8 How to Achieve Better Cohesion Some of this is just good OO experience We can learn from database normalization –Eliminate redundancy –Attributes should have a single value and should not have structure (repeating groups of things) –Attributes always describe an instance of its containing class That’s what attributes are all about! State values that define a particular instance Note: there are always tradeoffs! Sometimes we combine abstractions into one class for efficiency.

3/1/01H-9 Coupling How dependent an object/class is on the world around it –How many connections –Nature of the connections –Will changes cause a “ripple effect”? Our goals: –Reduce coupling if possible –Improve nature of necessary coupling

3/1/01H-10 Forms of Coupling (from Richter) Identity Coupling –An object contains a reference or pointer to another object –Eliminate associations or make them one-way Representational Coupling –An object refers to another through that object’s interface How it does this affects the degree of coupling

3/1/01H-11 Forms of Coupling (cont’d) Subclass Coupling –Object refers to another object using a subclass reference for that object Not the more general superclass –A client should refer to the most general type possible Why? Subclasses may be added later, possibly by someone else –Try to write code that minimizes dependencies on subclass details Instead rely on the common interface defined in the superclass Factory patterns for creation

3/1/01H-12 Interfaces Java’s interfaces; C++ classes with pure virtual functions and no data members Interfaces define a role not a class-abstraction –Many classes can pay that role We can define a function parameter or pointer in terms of the role (interface) instead of the class type

3/1/01H-13 Forms of Coupling (cont’d) Inheritance coupling –A subclass is coupled to its superclass at compile-time In general, prefer late to early –Seems like the only way to do things, but ask: While the program executes, does an object need to change its subclass? –Aggregation is supported at run-time –Examples: PARTS: subclasses for Manager and Employee?

3/1/01H-14 Generalization/Specialization: When? Why might you choose to introduce a super-class? –A true “Is-A” relationship in the domain model –Two or more classes share a common implementation Rule: “Write once!” –Two or more classes share a common interface Can use super-class as parameter type But interfaces solve this problem too A subclass specializes its super-class by one of: –Adding state info in terms of an attribute –Adding state info in terms of an association –Adding behavior in terms of a new method –Replacing behavior by overriding a method

3/1/01H-15 Generalization/Specialization: When Not? Avoid distinctions based on state of an instance Why? Objects change state! Solutions: –Replace with aggregation. How? –Factor out state-specific “extensions” to attributes and operations into a second object –Attach that object as needed Example: the State design pattern from the Gang of Four book

3/1/01H-16 The State Design Pattern A connection can be in various states –Handles requests differently depending on state Connection delegates requests to its state object –Which changes dynamically

3/1/01H-17 Generalization/Specialization: When Not? (2) Concrete super-classes are often a bad idea –Consider example of Manager as a sub-type of Employee –Implies Managers inherit every property of Employee Nothing can be unique to non-Managers! Reminder: Specialization along multiple dimensions is often better done with aggregation –See earlier example of Account and Customer

3/1/01H-18 Generalization/Specialization: When Not? (3) Where to place properties that are common to some but not all subclasses? –This can get ugly! (Example in Richter’s textbook, Sect 4.3.2) –Intermediate subclasses? Mix-in classes? Helper classes? Do not (repeat, do not) use multiple inheritance when it’s really aggregation –Ask the “Is-A” question. –Liskov substitutability principle: An instance of a child class can mimic the behavior of the parent class and should be indistinguishable from an instance of the parent class if substituted in a similar situation.

3/1/01H-19 Coad’s Five Criteria for When to Inherit Peter Coad in book Java Design Encapsulation is weak within a class hierarchy Only use inheritance when: –“Is a special kind of”, not “Is a role played by”. –Never need to transmute an object to be in some other class –Extends rather than overrides or nullifies –Does not subclass what is merely a utility class –For problem domain (PD) objects, it is a special kind of role, transaction, or thing

3/1/01H-20 Example: Java’s Observer/Observable Coad argues Java’s implementation of this design pattern is poor. Observer interface: public interface Observer { void update (Observable observed, Object argument); } Observable superclass. Has operations: addObserver(), deleteObserver(), deleteObservers(), notifyObservers()

3/1/01H-21 Class Diagram: Observable/Observer Top two classifiers from java.util

3/1/01H-22 Java’s Observable Superclass Does it meet Coad’s criteria? No! –We’re subclassing a utility class A better implementation: –Make Observable an interface (not a superclass) –Factor out the “observable-related” stuff into an ObservableComponent object This is a reusable utility class Implements storing and notifying observers

3/1/01H-23 Observable Interface, ObservableComponent Class

3/1/01H-24 Coad’s Observer Interface Java’s Observer interface won’t work with this model: public interface Observer { void update (Observable theObserved, Object argument); } First parameter is an Observable –We need it to be anything that implements our IObservable interface Coad’s solution: Replace with a new Observer interface that looks like this: public interface IObserver { void update (Object theObserved, Object argument); } Or, should it be IObservable theObserved ???