Introduction to Unified Modelling Language (UML) (part 2 Class diagram, Associations)
Objects What are Objects Observations “a discrete entity with a well-defined boundary that encapsulates state and behaviour; an instance of a class” UML Reference Manual, 2nd Edition-2004 Observations an instance of a class state is maintained in fields behaviour is implemented via methods every object is uniquely identified
UML Object Notation
Classes What are Classes “the descriptor for a set of objects that share the same attributes, operations, methods, relationships, and behaviour” UML Reference Manual, 2nd Edition-2004 template for objects with similar features
UML Class Notation
UML Class Notation
How Much to Show? Scenarios scenario 1: inter-class relationship scenario 2: behaviour of a class or classes scenario 3: entity classes representing data entities
How Much to Show? Scenarios scenario 1: inter-class relationship class boxes are probably enough with name compartment only scenario 2: behaviour of a class or classes class boxes with name & operations compartment
Analysis Classes What is an Analysis Class? represents an important concept of the problem domain maps on to real-world concepts an attempt to capture the big picture
Analysis Classes
Analysis Classes Observations name reflects the intent of abstraction focus clearly defined/understood small & well defined set of responsibilities high cohesion & low coupling
Classes The three class types in the Unified Process are UML notation Entity classes Boundary classes Control classes UML notation
Entity Classes An entity class models information that is long lived Examples: Account Class in a banking information system Mortgage Class and Investment Class in the information system Instances of all these classes remain in the information system for years
Boundary Classes A boundary class models the interaction between the information system and its actors Boundary classes are generally associated with input and output Examples: Sales Report Class in the E-Commerce information system Mortgage Listing Class and Investment Listing Class in the information system
Control Classes A control class models complex computations and algorithms Examples: Compute GPA Student Class, in the PSU information system
Stereotypes UML notation for these three types of classes These are stereotypes (extensions of UML) UML allows us to define additional constructs that are not part of UML but which we need in order to model a system accurately
The Unified Process and Classes The Unified Process does not describe how classes are extracted Users of the Unified Process are expected to have a background in object-oriented analysis and design We temporarily suspend this discussion of the Unified Process to explain how classes are extracted, and then return to the Unified Process
Extracting Entity Classes Entity class extraction consists of three steps that are carried out iteratively and incrementally: Functional modeling Present scenarios of all the use cases (a scenario is an instance of a use case) Class modeling Determine the entity classes and their attributes Determine the interrelationships and interactions between the entity classes Present this information in the form of a class diagram Dynamic modeling Determine the operations performed by or to each entity class Present this information in the form of a statechart
Flowchart for Extracting Entity Classes
Initial Class Diagram: Painting System Case Study The second step in extracting the entity classes is class modeling The aim of this step is to extract the entity classes, determine their interrelationships, and find their attributes Usually, the best way to begin this step is to use the two-stage noun extraction method Stage 1: Describe the information system in a single paragraph Stage 2: Identify the nouns in this paragraph, then select the entity classes from those nouns
Noun Extraction: Painting System Case Study Stage 1: Describe the information system in one paragraph: Reports are to be generated in order to improve the effectiveness of the decision-making process for buying works of art. The reports contain buying and selling information about paintings, which are classified as masterpieces, masterworks, and other paintings
Noun Extraction: Painting System (contd) Stage 2: Identify the nouns in this paragraph Reports are to be generated in order to improve the effectiveness of the decision-making process for buying works of art. The reports contain buying and selling information about paintings, which are classified as masterpieces, masterworks, and other paintings The nouns are report, effectiveness, process, buying, work of art, selling, information, painting, masterpiece, and masterwork
Noun Extraction: Painting System (contd) effectiveness, process and information are abstract nouns and are therefore unlikely to be entity classes Abstract nouns identify things that have no physical existence Nouns buying and selling are derived from the verbs “buy” and “sell” They will probably be operations of some class
Noun Extraction: Painting System (contd) Noun report is unlikely to be an entity class, because a report is not long lived A report is much more likely to be a boundary class Noun work of art is just a synonym for painting
First Iteration of the Initial Class Diagram This leaves four candidate entity classes: Painting Class, Masterpiece Class, Masterwork Class, and Other Painting Class
Second Iteration of the Initial Class Diagram Consider the interrelationships between the entity classes A masterpiece is a specific type of painting, and so is a masterwork and an “other painting” Painting Class is therefore the base class Masterpiece Class, Masterwork Class, and Other Painting Class are subclasses of that base class
Second Iteration of Initial Class Diagram (contd)
Third Iteration of the Initial Class Diagram The class diagram does not reflect aspects of the pricing algorithm When dealing with a masterwork “The information system first computes the maximum purchase price as if it were a masterpiece by the same artist”
Third Iteration of the Initial Class Diagram (contd) That is, a masterwork has to have all the attributes of a masterpiece (so that its maximum purchase price can be computed as if it were a masterpiece) and, in addition, it may have attributes of its own This is modeled in the next slide
Third Iteration of the Initial Class Diagram (contd)
Fourth Iteration of the Initial Class Diagram Another aspect of the pricing algorithm that is not reflected in the current class diagram is “The information system computes the coefficient of similarity between each painting for which there is an auction record and the painting under consideration for purchase”
Fourth Iteration of the Initial Class Diagram (contd) Auctioned Painting Class is needed to make these comparisons An auctioned painting must be a subclass of Painting Class But a painting previously been sold at an auction somewhere in the world has nothing to do with paintings currently on display for sale in Osbert’s gallery
Fourth Iteration of the Initial Class Diagram (contd)
Fourth Iteration of the Initial Class Diagram (contd) An instance of Painting Class is either A painting that Osbert has bought (an instance of Gallery Painting Class), or A painting sold at some auction (an instance of Auctioned Painting Class)
Initial Class Diagram: Painting System Case Study Why was the first iteration of the class diagram so inadequate? The Painting System case study appears to be a straightforward data-processing application The one-paragraph description correctly did not incorporate the pricing algorithm Unfortunately, the algorithmic details turned out to be critical to the class diagram
Initial Class Diagram: Painting System (contd) The first iteration of the class diagram was no good However, repeated iteration and incrementation led to a reasonable class diagram This demonstrates the power of the iterative and incremental approach
Initial Class Diagram (contd) Finally, we add the attributes of each class to the class diagram the result is shown on the next slide The empty rectangle at the bottom of each box will later be filled with the operations of that class
Fifth Iteration of the Initial Class Diagram (contd)
Fifth Iteration of the Initial Class Diagram (contd)
Done with the Painting System case study Still the dynamic modeling – later
Design Classes What is a Design Class? Integrates the problem domain & solution domain problem domain → refined analysis classes solution domain → implementation specific classes are complete, ready to be implemented
Design Classes Concerns responsibility inheritance the public methods imply a contract code evolution should be considered inheritance major concern of design classes (why?)
Inheritance Concerns the strongest form of coupling between classes “fragile base class” problem changes in the base class impact subclasses inflexible to change fixed at runtime
Example: Ambitious John
Inheritance or Interface interface & implementation concerns with reuse Interface interface only concerns with functionality contract “design by contract” concerns with reuse (what?)
Further Considerations Student Self-Study Templates Nested classes Multiple Inheritance
connection between two things (usually classes) What is an Association? connection between two things (usually classes) “for a link between two object, there must be an association between the class of those objects” link is an instance of an association link can be represented by dependency relationship
Example
Reflexive Association
Reflexive Association
Aggregation
Composition
Association Classes
Association Classes Observations association classes are purely analysis classes convert association class into normal design class use the various relationships to clarify association (aggregation, composition, dependency) additional constraints to refine the model navigation, multiplicity