Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes (continued)

Slides:



Advertisements
Similar presentations
UML Class Diagram. UML Class Diagrams2 Agenda What is a Class Diagram? Essential Elements of a UML Class Diagram Tips.
Advertisements

Use Case Diagram © copyright 2001 SNU OOPSLA Lab..
Chapter 6: Using Design Patterns
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 5: Restaurant.
Chapter 8: Modelling Interactions and Behaviour
1 Object-Oriented Design. 2 Objectives F To become familiar with the process of program development. F To the relationship types: association, aggregation,
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes.
Modeling Dynamic Behavior: Sequence and Collaboration Diagrams.
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
BIS310: Week 7 BIS310: Structured Analysis and Design Data Modeling and Database Design.
Object-Oriented Analysis and Design
Anyone know what type of planes these are? © Lethbridge/Laganière 2005 Chapter 5: Modelling with classes1 Douglas DC-3.
Chapter 9 Domain Models. Domain Model in UML Class Diagram Notation A “visual dictionary”
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented Design.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
CSCI-383 Object-Oriented Programming & Design Lecture 9.
Big Java Chapter 12. Software Process - Waterfall Analysis Design Implementation Testing Deployment Does not work well when rigidly applied! established.
Chapter 5: Modelling with Classes
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes.
Chapter 6 Use Cases. Use Cases: –Text stories Some “actor” using system to achieve a goal –Used to discover and record requirements –Serve as input to.
Lecture 5: Modelling with Classes. © Lethbridge/Laganière 2005 Chapter 5: Modelling with classes2 5.1 What is UML? The Unified Modelling Language is a.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes.
Systems Analysis and Design in a Changing World, 3rd Edition
CS3773 Software Engineering Lecture 04 UML Class Diagram.
Conceptual Modeling Modeling the Problem Domain. Conceptual Modeling Decompose problem space into comprehensible concepts. Clarify the terminology or.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Unified Modeling Language © 2002 by Dietrich and Urban1 ADVANCED DATABASE CONCEPTS Unified Modeling Language Susan D. Urban and Suzanne W. Dietrich Department.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes.
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.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes.
Lecture 1: UML Class Diagram September 12, UML Class Diagrams2 What is a Class Diagram? A class diagram describes the types of objects in the system.
CSE 240 Lecture 5. © Lethbridge/Laganière 2001 Chapter 5: Modelling with classes2 Overview Discuss Assignment 1 Discuss more of chapter 5, possibly finish.
Design Model Lecture p6 T120B pavasario sem.
Object Oriented Analysis and Design Class and Object Diagrams.
Object-Oriented Analysis and Design CHAPTERS 9, 31: DOMAIN MODELS 1.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
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.
ITEC324 Principle of CS III Chapter 2 (Horstmann’s Book) – Part 1 The Object-Oriented Design Process Hwajung Lee.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Object-Oriented Design.
Domain Model A representation of real-world conceptual classes in a problem domain. The core of object-oriented analysis They are NOT software objects.
Object-Oriented Software Engineering Practical Software Development using UML and Java Modelling with Classes.
Kyung Hee University Class Diagramming Notation OOSD 담당조교 석사과정 이정환.
High Level Design Use Case Textual Analysis SE-2030 Dr. Mark L. Hornick 1.
UML Fundamental Elements. Structural Elements Represent abstractions in our system. Elements that encapsulate the system's set of behaviors. Structural.
Class Diagrams Revisited. Parameterized Classes Parameterized Classes - are used to represent relationships between templates.
Modelling with Classes Adapted after : Timothy Lethbridge and Robert Laganiere, Object-Oriented Software Engineering – Practical Software Development using.
1 The Process of Developing Class Diagrams You can create UML models at different stages and with different purposes and levels of details Exploratory.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes Based on Presentations LLOSENG.
Chapter 2 (Horstmann’s Book) – Part 1 The Object-Oriented Design Process Hwajung Lee.
CSCE 240 – Intro to Software Engineering Lecture 3.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes.
Classes and their relationships
Chapter 9 Domain Models.
Chapter 5: Modelling with Classes
Chapter 11 Object-Oriented Design
UML Class Diagram.
Chih-Ping Chu Dept. of Computer Science & Information Engineering
ITEC324 Principle of CS III
Chapter 5: Modelling with Classes
Presentation transcript:

Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes (continued)

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes2 5.8 The Class Diagram Design Process You can create UML models at different stages and with different purposes and levels of detail Exploratory domain model: —Helps to learn about the domain E.g., Registration System domain model: —Shows aspects of the domain covered by the system E.g., Student, TimeSlot, Instructor, CourseOffering System model: —Includes classes for the user interface and system architecture E.g., course and transcript databases, client-server classes

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes3 System domain model vs System model The system domain model omits many classes that are needed to build a complete system —Can contain less than half the classes of the system —Should be developed independently of particular -user interface classes -architectural classes (client-server, database, etc.) The complete system model includes —The system domain model —User interface classes —Architectural classes —Utility classes

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes4 Sequencing of Design Activities 1.Identify a first set of candidate classes 2.Add associations and attributes 3.Find generalizations 4.List the main responsibilities of each class 5.Decide on specific operations 6.Iterate over this process until the model is satisfactory —Add or delete classes, associations, attributes, generalizations, responsibilities or operations —Identify interfaces —Apply design patterns (Chapter 6) Don’t be too disorganized. Don’t be too rigid either.

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes5 Identifying classes 1.When developing a domain model you tend to discover classes (i.e., they already exist) 2.When you work on the user interface or the system architecture, you tend to invent classes —Needed to solve a particular design problem —(Inventing also occurs in domain modeling) 3.Reuse should always be a concern —Frameworks —System extensions —Similar systems

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes6 Tips on discovering domain classes 1.Look at a source material such as a description of requirements 2.Extract the nouns and noun phrases 3.Eliminate nouns that: —are redundant —represent instances —are vague or highly general —not needed in the application 4.Pay attention to classes that represent types of users or other actors

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes7 Identifying associations and attributes 1.Start with classes you think are most central 2.Decide on the obvious data each class must contain and its relationships to other classes. 3.Work outwards toward classes that are less important. 4.Avoid adding too many associations/attributes to a class (A system is simpler if it has less information) 5.An association exists if a class -possesses / controls -is connected to / is related to -is a part of / has as parts -is a member of / has as members another class in the model 6.Specify multiplicity at both ends 7.Label the association clearly

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes8 Actions versus associations A common mistake is to represent actions as if they were associations Bad: associations are not actions * LibraryPatron borrow **** * return CollectionItem * * Loan borrowedDate dueDate returnedDate LibraryPatron CollectionItem * * Better: Borrow is replaced by a Loan and a borrowedDate, and return sets the returnedDate.

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes9 Identifying attributes Look for information that must be maintained about each class Several nouns rejected as classes, may now become attributes An attribute should usually contain a simple value —E.g. string, number, date

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes10 Identifying and specifying valid attributes Avoid having many duplicate attributes If a group of attributes is coherent, create a distinct class with these attributes. E.g.,

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes11 Example: attributes and associations * supervisor RegularFlight time flightNumber * ****** Passenger ****** ****** ****** SpecificFlight date name employeeNumber Employee jobFunction Booking seatNumber name number

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes12 Identifying generalizations and interfaces Two ways to identify generalizations: —bottom-up: group similar classes to create a new superclass —top-down: find general classes first; specialize them if needed Create an interface instead of a superclass, if: —The classes have only a few operations in common —The classes already have their own superclasses —Different implementations of the same class might be available

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes13 An example (generalization) * supervisor RegularFlight time flightNumber * ****** PassengerRole ****** ****** ****** SpecificFlight date Person name idNumber 0..2 EmployeeRole jobFunction Booking seatNumber PersonRole

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes14 Assigning responsibilities to classes A responsibility is something that the system is required to do. Every functional requirement must be assigned to a class —All of a class’s responsibilities should be clearly related. —A class with too many responsibilities can be split into two classes —A class with no responsibilities is probably useless —When a responsibility cannot be attributed to any of the existing classes, then a new class should be created —A responsibility usually denotes a public method or constructor. To find responsibilities: —Read the use cases, and —Look for verbs and nouns describing actions in the system description

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes15 Kinds of responsibilities for classes Setting and getting the values of attributes Creating and initializing new instances (constructors) Loading to and saving from persistent storage (file i/o) Destroying instances - destructors (automatic in Java) Adding and deleting links of associations Copying, converting, transforming, transmitting or outputting Computing numerical results Navigating and searching Other specialized work

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes16 An example (responsibilities) —Creating a new regular flight —Searching for a flight —Modifying attributes of a flight —Creating a specific flight —Booking a passenger —Canceling a booking

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes17 Prototyping a class diagram in Eclipse 1.Open a new.ucd file in a package of a project. 2.As you identify classes, create and name them in the workspace 3.As you identify attributes and responsibilities, add them to the classes where they belong. — If you cannot fit all the responsibilities into one class, consider creating two related classes. 4.Move the classes around on the workspace to arrange them into a class diagram. 5.Draw lines between the classes to capture associations and generalizations.

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes18 Identifying operations (methods) Operations realize the responsibilities of each class There may be several operations per responsibility The main methods that implement a responsibility are normally the public ones Other methods that collaborate to perform the responsibility must be as private as possible

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes19 An example (modeling class collaborations) Airplane addLinkToSpecificFlight [a2, d3] deleteLinkToSpecificFlight [d2] SpecificFlight + specifyAirplane [a1] + createFlightLog [b1] + makeBooking [c1] + changeAirplane [d1] + findCrewMember [e1] EmployeeRole + getName [e2] FlightLog FlightLog [b2] Booking Booking [c2] PassengerRole addLinkToBooking [c4] * ****** 0..1 * * ****** crewMember 0..1 addLinkToBooking [c3]

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes20 Class collaboration A Making a bi-directional link between two existing objects; e.g. adding a link between an instance of SpecificFlight and an instance of Airplane. 1.(public) The instance of SpecificFlight —makes a one-directional link to the instance of Airplane —then calls operation 2. 2.(non-public) The instance of Airplane —makes a one-directional link back to the instance of SpecificFlight

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes21 Class collaboration B Creating an object and linking it to an existing object e.g. creating a FlightLog, and linking it to a SpecificFlight. 1. (public) The instance of SpecificFlight —calls the constructor of FlightLog (operation 2) —then makes a one-directional link to the new instance of FlightLog. 2. (non-public) Class FlightLog ’s constructor —makes a one-directional link back to the instance of SpecificFlight.

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes22 Class collaboration C Creating an association class, given two existing objects e.g. creating an instance of Booking, which will link a SpecificFlight to a PassengerRole. 1.(public) The instance of PassengerRole —calls the constructor of Booking (operation 2). 2.(non-public) Class Booking ’s constructor, among its other actions —makes a one-directional link back to the instance of PassengerRole —makes a one-directional link to the instance of SpecificFlight —calls operations 3 and 4. 3.(non-public) The instance of SpecificFlight —makes a one-directional link to the instance of Booking. 4.(non-public) The instance of PassengerRole —makes a one-directional link to the instance of Booking.

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes23 Class collaboration D Changing the destination of a link e.g. changing the Airplane of to a SpecificFlight, from airplane1 to airplane2 1. (public) The instance of SpecificFlight —deletes the link to airplane1 —makes a one-directional link to airplane2 —calls operation 2 —then calls operation (non-public) airplane1 —deletes its one-directional link to the instance of SpecificFlight. 3. (non-public) airplane2 —makes a one-directional link to the instance of SpecificFlight.

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes24 Class collaboration E Searching for an associated instance e.g. searching for a crew member associated with a SpecificFlight that has a certain name. 1.(public) The instance of SpecificFlight —creates an Iterator over all the crewMember links of the SpecificFlight —for each of them call operation 2, until it finds a match. 2.(may be public) The instance of EmployeeRole returns its name.

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes Implementing Class Diagrams in Java 1.Attributes are implemented as instance variables 2.Generalizations are implemented using extends 3.Interfaces are implemented using implements 4.Associations are normally implemented using instance variables Divide each two-way association into two one-way associations —so each associated class has an instance variable. For a one-way association where the multiplicity at the other end is ‘one’ or ‘optional’ —declare a variable of that class (a reference) For a one-way association where the multiplicity at the other end is ‘many’: —use a collection class implementing List, such as Vector

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes26 Example: SpecificFlight class SpecificFlight { private Calendar date; private RegularFlight regularFlight; private TerminalOfAirport destination; private Airplane airplane; private FlightLog flightLog; private ArrayList crewMembers; // of EmployeeRole private ArrayList bookings... }

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes27 Example: SpecificFlight // Constructor that should only be called from // addSpecificFlight SpecificFlight( Calendar aDate, RegularFlight aRegularFlight) { date = aDate; regularFlight = aRegularFlight; }

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes28 Example: RegularFlight class RegularFlight { private ArrayList specificFlights;... // Method that has primary // responsibility public void addSpecificFlight( Calendar aDate) { SpecificFlight newSpecificFlight; newSpecificFlight = new SpecificFlight(aDate, this); specificFlights.add(newSpecificFlight); }... }

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes29 Initial StressFree domain model: some classes