Presentation is loading. Please wait.

Presentation is loading. Please wait.

MCS 270 Spring 2014 Object-Oriented Software Development.

Similar presentations


Presentation on theme: "MCS 270 Spring 2014 Object-Oriented Software Development."— Presentation transcript:

1 MCS 270 Spring 2014 Object-Oriented Software Development

2 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Today’s schedule Basics of UML Class Diagrams MCS 270 Object-Oriented Software Development

3 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Unified modeling language (UML) 1980’s and 90’s - Several competing object-oriented notations (Babel of notation) 1994 - Rumbaugh (one of our textbook’s authors) and Booch began working at IBM Rational to standardize their notations (OMT and Booch) Result was Unified Modeling Language (UML) Rights owned by Object Management Group (OMG), www.omg.org www.omg.org MCS 270 Object-Oriented Software Development

4 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Collection of notations representing software designs from three points of view: Class model State model Interaction model Generally need all three models to describe a system No single model describes everything in problem domain Unified modeling language (UML) MCS 270 Object-Oriented Software Development

5 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Class model: describes the static structure of objects and relationships in a system Comprises object and class diagrams State model: describes the dynamic aspects of objects and the nature of control in a system Interaction model: describes how objects in a system cooperate to achieve broader results Unified modeling language (UML) MCS 270 Object-Oriented Software Development

6 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Class Model MCS 270 Object-Oriented Software Development

7 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Good Class/Object Design Meaningful concept or “thing” in an application domain Has identity that does not encapsulate an object within itself, does not use attribute values of another object Classes model relationships among things in domain MCS 270 Object-Oriented Software Development

8 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Good Class/Object Design What is wrong with this definition of a city class? MCS 270 Object-Oriented Software Development City cityName : String population : int timeZone : String airportName : String airportCode : String

9 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Good Class/Object Design What is wrong with this definition of a city class? MCS 270 Object-Oriented Software Development City cityName : String population : int timeZone : String airportName : String airportCode : String Answer: These attributes “hide” an object (i.e., an airport) that is meaningful in this domain

10 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Question Why might it be bad to encode one object as a collection of attribute values within another? MCS 270 Object-Oriented Software Development

11 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Question Why might it be bad to encode one object as a collection of attribute values within another? Potential for redundancy/inconsistency some airports serve multiple cities some cities served by no airports some cities served by multiple airports Operations over Airport objects may not need to know details associated with cities, such as population MCS 270 Object-Oriented Software Development

12 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Design tip When designing a class: Apply the identity test to each attribute (does attribute belong to class?) Never use an attribute to model another object attribute UML notation helps enforce this discipline Next: how do we model connections between objects, such as Cities and Airports? MCS 270 Object-Oriented Software Development

13 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Relationships among objects Link: Physical or conceptual connection between objects Most (not all) links relate exactly two objects Association: Description of a group of links with common structure and semantics A link is an instance of an association: Links connect objects Association describes set of potential links just as a class describes a set of potential objects MCS 270 Object-Oriented Software Development

14 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Examples of links Houston : City cityName = “Houston, TX” population = 3000000 HOU : Airport airportCode = “HOU” airportName = “Hobby” timeZone = “Central” IAH : Airport airportCode = “IAH” airportName = “Intercontinental” timeZone = “Central” Serves MCS 270 Object-Oriented Software Development

15 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu City cityName : String population : int Airport airportName : String airportCode : String timeZone : String Serves 1..** association name multiplicities Example of an association MCS 270 Object-Oriented Software Development

16 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Association End Names ProfessorUniversity EmployerEmployee End Names WorksFor Association Name A ssociation end name defines role of Object The class could play same or different roles in other associations. Ex: Professor could also be classified as Teacher MCS 270 Object-Oriented Software Development

17 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Association End Names ParentChild A ssociation end name is used for multiple references to same class 2* Person child * parent 0..2 Not advisable – only use one class to represent a person Better MCS 270 Object-Oriented Software Development

18 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu New abstraction: Generalization (Sub-Super) Employee first_name : String last_name : String hire_date : Date department : int Manager level : short group * 0..1 This is the “is-a” relation Relates class to one that is “more general” Open arrow points to Base Class Derived class inherits all attributes/operations of parent Relation is anti-symmetric and transitive MCS 270 Object-Oriented Software Development

19 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Cheat Sheet Book – front and back have summary of diagrams Handout – another summary with annotated explanations MCS 270 Object-Oriented Software Development

20 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Practice MCS 270 Object-Oriented Software Development

21 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Practice MCS 270 Object-Oriented Software Development

22 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Practice Groups of two: Create a class model to describe undirected graphs. An undirected graph consists of edges connecting pairs of vertices. MCS 270 Object-Oriented Software Development An undirected graph with 6 nodes and 7 edges en.wikipedia.org/wiki/Graph_(mathematics)

23 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Practice Groups of two: Create a class model to describe directed graphs. Here edges are directed from start to end. MCS 270 Object-Oriented Software Development A directed graph with 3 nodes and 3 edges en.wikipedia.org/wiki/Graph_(mathematics)

24 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Why do we use UML? A Picture = Rich Data Encoding: we think in pictures and can relate info quickly in figures Creative destruction: Diagrams are easily changed, programs not so much Employment: UML is used in the workplace MCS 270 Object-Oriented Software Development

25 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Design tips Use a UML diagram when: Brainstorming ideas Sharing ideas with team Saving blueprint of idea You can't find a bug in code Teacher/manager requires it MCS 270 Object-Oriented Software Development

26 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Design tips Keep it simple – only use UML when you need to Manage Complexity: Draw diagrams that give most value, e.g. do not draw a diagram for system with one or two classes. Likewise, do not put in all detail in first iteration. MCS 270 Object-Oriented Software Development

27 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Design tips Good design practice: switch back and forth between what is said in the diagram and what is allowable in the code Good Programming Practice: Plan code using links/associations rather than Java classes and methods. This is good training in abstraction! MCS 270 Object-Oriented Software Development

28 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Summary UML provides notations for modeling objects, classes, and associations of an application domain Diagrams represent models: more abstract than code useful for explanation/documentation MCS 270 Object-Oriented Software Development

29 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Assignments Friday - Read Chapter 5 in text. Homework: Chapter 3. Exercises 3.8, 3.11, and 3.12 Due Monday, Feb. 17 MCS 270 Object-Oriented Software Development


Download ppt "MCS 270 Spring 2014 Object-Oriented Software Development."

Similar presentations


Ads by Google