UML and WSDL for JISC e-Learning Projects INTRODUCTION TO UML Richard Hopkins rph@nesc.ac.uk NeSC Training Team Member Goals and Overview Goals – To enable you to understand the UML part of the first example To explain the context and overall approach for UML Overview UML History and concepts Simple use of most essential diagrams Requirements Structure Behaviour JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 2 History of UML Use of diagrams In any discipline for the construction of complex artefacts Need to use diagrams, as tools for Thinking Communicating As discipline matures, diagrams become Standardised – For effective communication between all practitioners Stylized – Specialised technical language for compact representation UML – M is for Models A diagram is a model of the (proposed) system A partial representation of some aspect of the system JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 3 History of UML Historically A variety of stylised diagram languages Each associated with a design methodology A formalised Process for arriving at a design E.g., for Object-oriented design (early 90’s) Grady Booch’s OOD – Object-Oriented Design James Rumbaugh’s OMT – Object-oriented Modelling and Design Ivar Jacobson’s OOSE – Object-Oriented Software Engineering Competing Methodologies Rather improbably – Rumbaugh joined Booch, with intention of merging their methods They bought out Jacobsonn’s company – Objectory These three aimed for a single Unified Method JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 4 Methodolgy vs Notation Generally need different methodologies for different contexts Small application in four weeks by single programmer Large system in four years by 200-strong development organisation Often “use of X methodology” was actually use of “X’s”notation with methodology appropriate to context Strong reasons for using the same notation Concept of Unified Method, changed to Unified Modelling Language JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 5 Methodology vs Notation UML is NOT a methodology UML is a notation for recording the results of A requirements gathering / design process Carried out using some methodology – maybe! Any kind of diagram can be used for any purpose that is useful Sufficiently general that could be used with any imaginable O-O methodology However, for concreteness we will assume a particular general methodology JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 6 An Overall Development Process Partially articulated requirements Capture Requirements Use Case Diag. Construct Model of Overall system Class Diag. Sequence Diag. Requirements Structure Behaviour These diagram types, and the process can be used both for Designing a new system Understanding an existing system JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 7 Requirements Overview UML History and concepts Simple use of most essential diagrams Requirements Structure Behaviour JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 8 Introducing the Library Example A computer system for a university library; some “facts” The library has members – Staff Students The library contains items Books possibly several copies of each book Some books are for short-term loan only – only students can do short-term loans Journals Only staff may borrow journals The functionalities include Keeping track of when items are borrowed/returned Allow users to search for a book and check availability JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 9 Some Queries The library has members – Staff Students Can someone be both? The library contains Do we mean copies? Books; possibly several copies of each book Some books are for short-term loan only – only students can do shortterm loans Journal Only staff may borrow journals The functionalities include Keeping track of when items are borrowed/returned Allow users to search for a book and check availability Is “user” something different from “member? Henceforth use “user” JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 10 Requirements Engineering Natural language statement of requirements is typically riddled with ambiguities and inconsistencies Requirements Engineering is the discipline of dealing with this Developing UML models helps with identifying and clarifying requirements But still depends on natural language documentation It helps, but does not guarantee complete consistent set of requirements JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 11 Requirements - Simple Use Cases Borrow Copy of book Update Catalogue BookBorrower Librarian An Actor – a user of the system, in a particular role “BookBorrower” is a role played by library members Usually a person, but could be another system An entity outside the system being modelled In web services – usually another web service A Use Case – A task that an actor needs to perform with the help of the system “Borrow Copy of Book” describes the successful outcome – there will be variants for the exception cases This Actor participates in this Use Case JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 12 Simple Use Cases Use Case Documentation Borrow Copy of book BookBorrower Use Case: Borrow copy of book. • A bookBorrower presents a book. • The system checks that the potential borrower is a member of the library, • and that s/he does not already have the maximum permitted number of books on loan. Update Catalogue Librarian • The maximum is 6 unless the member is is a staff member, in which case it is 12. • If both ckecks succeed, the system records that this library member has this copy of the book on loan. • Otherwise it refuses the loan. Not a very rich diagram – later on we will see richer diagrams Needs more explanation – associated documentation Limitations of natural language! JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 13 STRUCTURE Overview UML History and concepts Simple use of most essential diagrams Requirements Structure Behaviour JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 14 Structure - Class Design UML is for Object-Oriented Design The state of the system is a collection of Objects Each Object is an instance of a Class The structure of the system is characterised by the class and their inter-relationships Key is identifying the classes kinds of things manipulated within the system Standard Technique - Noun identification Take a concise description of the system Identify the words/phrases that denote things JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 15 Noun Identification Some Facts – The library contains books and journals. It may have several copies of a given book. The system must keep track of when items are borrowed and returned The system must allow users to borrow items subject to rules – A student can borrow up to six items … JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 16 Class Design – Which Nouns? Library NO – Not “within the system” System Rule Yes if rules are updatable No if rules are built in ☺ Book ☺ Journal ☺ ☺ ☺ Yes – All these are things which the system needs to track Although they are not independent – Journal is a special case of item Student is a special case of user Item User Student Here a “book”, “student” etc. within the system – Represents an actual entity in the external world Partially Tracks what is happening to the real world entity JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 17 Class Diagram User Student Student Item Staff Journal Book A box for each Class There are relationships between classes Otherwise don’t need a diagram!!! Specialisation/Generalisation User is a generalisation of both Student Staff Any instance of Student is also an instance of User Later we will see other class relationships JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 18 Class Attributes and Operations Item Book Title : String Journal Attribute – Information associated with each instance of the class – what’s important for understanding; not all that exists in a programming language class implementing it Each attribute will have a type JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 19 Class Attributes and Operations Item Book Title : String Journal copiesOnShelf() : Integer An operation – something that instances of this class can do, which can be externally invoked A unit of functionality which is externally exposed Equivalent to a Java Method copiesOnShelf() : Integer To provide the invoker with a number which is the number of copies of the book which are available for borrowing. copies(in onShelf:Bool, out copyNos[0..*] Integer) : Status UML terminology is message-passing An object’s operation is invoked by another object sending it a message JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 20 Web Services as Objects A WSDL definition corresponds to a class “a service type” An actual web service conforming to that definition is an instance of that class But service types are often not found by “noun identification” Often more by Identifying Functions, rather than things Legacy Overall domain understanding (guesswork / intuition) Notion of layered architecture Viewing a function-provider as a service object JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 21 Example some Web Services A Web services Framework for E-learning (surprise!) User Agents (layer) Portal Timetabling Library Authoring Tool ... Application Service (layer) Group Management Resource Discovery Resource Management Common Services (layer) Authentication Authorisation Search Messaging ... Naturally a domain noun? – Yes No (As perceived by domain non-expert!) JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 22 ... BEHAVIOUR Overview UML History and concepts Simple use of most essential diagrams Requirements Structure Behaviour JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 23 Behaviour - Sequence Diagrams To Document how objects work together to achieve an overall function of the system – An Interaction Diagram Each sequence diagram shows an example “walk-through” Typically for a use case Not for all of them For Complex situations Where clarification seems needed JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 24 Sequence Diagram - participants For Use Case : Borrow copy of book theUser: User theCopy: Copy theBook: Book BookBorrower Identify the participants External Actor from the use case Objects within the system This is an instance diagram – Name each object, and identify its class theUser – object which is the internal representation of the user playing the BookBorrower role “theUser : User” seems redundant, but could have several User participants JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 25 Sequence Diagram – Lifelines Book Borrower theUser: User theCopy: Copy theBook: Book t i m e 1: 2: 3: 4: Object existence lifeline Sending a message Period of activation The reply 1. BookBorrower invokes the use case – activating the corresponding User object, theUser 2. theUser tells theCopy object that it is now borrowed – it changes its state 3. theCopy tells theBook that it has been borrowed – its reduces its count of available copies 4. TheUser confirms success to BookBorrower The replies to 2 and 3 not shown because not particularly important, whereas the confirmation to external user is. JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 26 Sequence Diagram – Operations Book Borrower theUser: User theCopy: Copy theBook: Book t i m e 1: borrow(theCopy) 2: borrow() 3: borrowed() 4: borrowStatus Sending a message Object existence lifeline Period of activation The reply Associate with the message line – The information communicated Usually the operation invoked and possibly its parameters JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 27 Final Points UML is a language to enable expression Its up to you what you express and what you don’t Which cases you give sequence diagrams Which attributes you include for a class ... Based on maximising usefulness to the reader Rather than rigid rules But it maybe you organisation’s standards, rather than your personal judgement JISC UML/WSDL – Introduction to UML, 16th Nov. 2004 28