310 likes | 326 Views
Learn how to transition from Domain Models to Design Classes to Implementation Classes. Explore class diagram notations, refinement processes, and benefits of abstraction. Improve your reasoning and critiquing skills with visual representations.
E N D
Design Class Diagrams http://flic.kr/p/ar9z8F
What are you goingto learn about today? • How to go from • Domain Models • to Design Classes • to Implementation Classes • More class diagram notations and conventions • to make your Design Class Diagrams great! http://flic.kr/p/8JpkTg
Recall: Iterative development process We are here http://en.wikipedia.org/wiki/File:Iterative_development_model_V2.jpg
Object-Oriented Design “Define software objects and how they collaborate to satisfy their requirements” • You need to be able to reason about a design • To understand designer’s intent • To critique/improve the design
Source code not best medium for reasoning • Lots of redundancy and detail irrelevant for some program understanding tasks • Especially poor at depicting relationships among classes in OO programs Solution: Use abstract, visual representations—for example, Design Class Diagrams (DCDs)
Differences between Domain and Design models Attributetypes Navigability Operations compartment
Refinement process: Unfolding the design Domain Model refine Design Classes refine public class Register { private int id; private Sale currentSale; ... } public class Sale { private DateTime time; ... } Implementation
Refinement isnot mechanical Another possiblerefinement One possiblerefinement class City { ... protected: string cityName; unsigned population; }; class Airport { ... protected: string airportName; CODE airportCode; ZONE timeZone; }; multimap<City*, Airport*> cityServes; multimap<Airport*, City*> airportServes; class City { ... protected: string cityName; unsigned population; vector<Airport*> serves; }; class Airport { ... protected: string airportName; CODE airportCode; ZONE timeZone; vector<City*> serves; };
Benefits of refinement process • Postpones design decisions until ready to make them • Manages complexity • Less refined designs more abstract http://flic.kr/p/7WYW68
Now, I’m going to introduce a bunch of new class diagram notations and conventions to help you make your DCDs more expressive
Full format of attribute notation • visibilityname : typemultiplicity = default {property} • Examples:
Visibility • + Public • Any class that can see the containing class can see • - Private • Only containing class can see • # Protected • Only containing class and its descendants can see • ~ Package • Only classes within containing package can see
Full format of operation notation • visibilityname (parameters) : return-type {property} • Examples:
Modeling attributes and associations public class Register { private int id; private Sale currentSale; ... } public class Sale { private DateTime time; ... }
Modeling an ordered list {list} Multiplicity Properties:
Distinguish between data typesand non-data types! • Instances of data types are plain old values • Examples: integers, strings, dates, dollar amounts • No need to distinguish between two instances of the same dollar amount • Instances of non-data types have identity • Examples: Sale, Register, Airport, City, Employee • Even if two employees had the same name and salary, they would still be distinct instances • In Design Class Diagrams, model • attributes as data types • associations among non-data types
Omit setter and getter operationsfrom design classes • Added noise outweighs value • Assume you have them if you need them
Modelingconstructors In a sequence diagram, model as a create message
Generalization implies inheritance Objects of subclass have all attributes and methods of superclass
Modeling dependencies public class Foo { public void doX() { System.runFinalization(); ... } ... }
Modeling interfaces An interface is essentially an abstract class with only abstract, public operations (no attributes and no methods)
Modeling hashes with qualified associations • Multiplicities are different than usual: • (catalog, ID) 1 description • description 1 (catalog, ID) • Implies catalog 0..* description Key typeIf numbers, could be itemID : Integer
Modeling templates Binding notations:
Creating Design Classes • See the handout… http://flic.kr/p/5dfuqL
Summary • Design as refinement process • Too many class diagram notations and conventions to list http://flic.kr/p/YSY3X