Building System Models for RE Chapter 10 Modeling Conceptual Objects with Class Diagrams Building models for RE Chap.8: Goals Chap.9: Risks why ? how ? Chap.10: Conceptual objects on what? Chap.11: Agents who ? The object model Structural view of the system being modeled (as-is or to-be) Roughly, shows how relevant system concepts are structured and interrelated Represented by UML class diagram ... – “objects”, classes not in the OO design sense: RE is concerned with the problem world only ! – classes with no operations: data encapsulation is a design concern; no design decisions here ! Multiple uses ... – precise definition of system concepts involved in other views, their structure & descriptive properties – state variables manipulated in other views – common vocabulary – basis for generating a glossary of terms Modeling conceptual objects: outline What is a conceptual object? Entities BookCopy Associations & multiplicities Patron Attributes Patron Name Specialization StudentPatron Loan BookCopy Patron StaffPatron Aggregation More on class diagrams Library BookCopy – derived attributes, OR-associations, associations of associations Building object models: heuristic rules What is a conceptual object? Set of instances of a system-specific concept ... – distinctly identifiable • immutable, built-in identity • e.g. 2 string instances “Justine Henin” are the same, but 2 Patron instances named Justine Henin are different – can be enumerated in any system state • in any state we can list all instances of the Patron concept currently involved in the system – share similar features • common name, definition, type, domain properties, • common attributes, associations: see details later e.g. Email attrib of Patron; Loan assoc linking Patron and BookCopy – may differ in their individual states and state transitions Object instantiation: classes & current instances Every conceptual object has a built-in semantic relation telling which instances are currently members of the object: InstanceOf (o, Ob) iff o is currently an instance of Ob – kept implicit in the object model, used for Def specification – “current” state = some arbitrarily chosen system state – e.g. InstanceOf (bc, BookCopy) says bc is currently member of set BookCopy of book copies manimulated in the library system – might not be the case 3 weeks earlier or 1 year later ... A set of object instances may evolve over time An instance may migrate from one object to another – e.g. StudentPatron instance StaffPatron instance An instance may be member of multiple objects Object instantiation: classes & current instances (2) Every concept in object model must be defined by Def annotation specifying the necessary & sufficient condition for an individual to satisfy InstanceOf (o, Ob) – i.e. specific conditions for individual to appear & disappear as instance of this object – e.g. “ A patron is any person who has registered to the corresponding library for the corresponding period of time and has not been excluded since then“ When an individual becomes instance of an object, the object’s attributes & associations get instantiated as state variables to characterize it e.g. InstanceOf (tr, Train) tr.Speed, tr.DoorsState, On (tr, ...) State variables of the system = set of state variables of all conceptual objects declared in the object model Types of conceptual object Entity: autonomous, passive object – instances may exist in system independently of instances of other objects – instances cannot control behavior of other objects – e.g. Book, BookCopy ; Train, Platform, ... – represented as UML class Association: object dependent on objects it links – instances are conceptual links among object instances – e.g. Loan linking Patron & BookCopy Copy linking BookCopy & Book At linking Train & Platform On linking Train & Block – represented as UML association Types of conceptual object (2) Event: instantaneous object – instances exist in single system state InstanceOf (ev, Ev) denoted by Occurs (Ev) – e.g. BookRequest ; StartTrain – represented as UML class if attributes, associations needed Agent: active, autonomous object – instances have individual behavior = sequence of state transitions for state variables they control – e.g. Patron, Staff ; TrainController, TrainDriver – represented as UML class if attributes, associations needed O bject S ubtype E ntity A ssociation A ge nt E vent Object features as model annotations a g en t P a tro n Nam e fea tu res E m a il a ttribu tes en tity T ra in Speed A cc e le ra tio n D o o rs S tate N a m e T ra in ; T yp e E n tity D e f A n y tra in c u rre n tly in o p e ra tio n in th e sys te m . Has Speed % … % ; A cc e le ra tio n % … % ; D o o rs S ta te % … % ; D o m In v a r a n no tation a sso cia tion On N a m e P atro n ; T yp e A g e n t D e f A n y p e rs o n c u rre n tly re g is te re d to a s ystem ’s lib ra ry fo r s om e va lid p e rio d . S yn o n ym s B o rro w e r M o vin g IffN o n Z e ro S p e e d : ( tr: T ra in ) (M o vin g (tr) tr.S p e e d 0 ) N o n Z e roS p e e d IfN o n Z e ro A c c e le r: ( tr: T ra in ) (tr.A cc e le ra tio n 0 tr.S p e e d 0 ) C los e d IfN o tO p e n : ( tr: T ra in ) (tr.D o o rs S ta te ‘o p e n ’ tr.D o o rs S ta te = ‘c los e d ’) In it F o r a n y tra in tr: tr.S p e e d = 0 tr.A cc e le ra tio n = 0 tr.D o o rs S ta te = ‘c los e d ’ Is s u e H o w a b o u t tra ins u n d e r m a in te n a n c e ? B lo ck … Nam e O n D e f T h e c u rre n t lo c a liza tio n o f a tra in o n sys te m b loc ks . D o m In v a r O n T w oB lo cks A tM os t: A tra in is o n o n e o r tw o s u cc e ss ive b lock s a t a n y tim e . In it A n y tra in e n te rin g th e s ystem is o n th e m ain s ta tio n b loc k Entities As seen before: autonomous, passive object – instances may exist in system independently of instances of other objects – distinctly identifiable, can be enumerated in any system state, share similar features, may differ in individual states & transitions – instances cannot control behavior of other objects – characterized by Def, domain invariants, attributes, initialization In the Def annotation, the conditions for an individual to appear & disappear as instance of this entity must not necessarily refer to other objects in the model Library Train BookCopy Block Associations Association = conceptual object linking other objects, each playing specific role – dependent on objects it links – linked objects may be entities, associations, events, agents roles Train holdsTrain isOn On Block Association instance = tuple of linked object instances, each playing corresponding role – may currently exist only if all instances are currently linked and currently instances of corresponding objects Predicate notation Assoc (o1, ..., on) for InstanceOf ([o1, ..., on], Assoc) Association instances Association instance = tuple of linked object instances, each playing corresponding role Train holdsTrain isOn On Block InstanceOf tr1 tr2 On (tr2,bl1) bl1 On (tr1,bl3) bl2 bl3 Associations & their instances Like for any object, association instances ... – are distinctly identifiable • built-in immutable identity = tuple of identities of linked object instances – can be enumerated in any system state – are characterized by common features • name, definition, attributes, domain invariants, initializations – evolve individually from state to state ... • instance appears as Ass (o1, ..., on) gets true (link creation) • instance disappears as Ass (o1, ..., on) gets false (link deletion) • state change as values of attached attrib, assoc are changing Associations (2) Arity of association = number of objects linked by it – Binary associations: arity = 2 – N-ary associations: arity > 2 • needed when links involving more than 2 objects must be distinguished • e.g. Registration linking ... Patron (role MemberOf) Library (role hasMember) Period (role ValidityPeriod) if binary, no distinction possible among registrations of same patron & library for different periods Reflexive association = same object appears under different roles – e.g. Following linking Train (role Follows), Train (role FollowedBy) Multiplicities of n-ary association From fixed source (n-1)-tuple of currently linked instances: min/max number of linked target instances – attached to role of target instance For binary associations, express standard constraints ... – min = 0: optional link (possibly no link in some states) – min = 1: mandatory link (at least one link to target in any state) – max = 1: uniqueness (at most one link to target in any state) – max = *: arbitrary number N of target instances linked to source instance, in any state (N > 0) Notation: “k” for “k..k”, “*” for “0..*” Borrows BorrowedBy Patron O..1 Loan O..Max BookCopy Entities, associations in UML Command association * Driving Car In 1 Train a block may hold 0 or 1 train 0..1 isOn * On 1..2 Block holdsTrain At Platform 0..1 entity a train may be at 0 or 1 platform at most Entities, agents, associations in UML for a given libary and registration period, there may be 0 up to an unbounded number of registered patrons Patron agent Loan 0..1 0..Max Borrows BorrowedBy BookCopy * * Period 0..1 1..* Library Registration n-ary association (2) Copy 1 Book Multiplicities, domain properties and goals Multiplicities may encode some ... – domain properties (descriptive) "A train may be at one platform at most at a time" – goals (prescriptive) "A block may not accommodate more than one train at any time” "A patron may not borrow more than Max book copies at a time” to be found in the goal model as well ! => source for goal elicitation (parent goals ?, subgoals ?) BUT ... – multiplicities mix prescriptive & descriptive assertions – most assertions are not expressible by multiplicities "A borrowed book must be returned within 2 weeks” “A copy may not be both borrowed and available” need for other domain invariants, goals/requirements Attributes Intrinsic feature shared by any instance of an object – entity, association, event, agent (like associations) An attribute Att of object Ob is a function: Att: Ob SORT Sort: set of possible attribute values (function range) – NOT a conceptual object we want to model – may be declared by ... • predefined, domain-independent name CopyAvailable: Boolean PatronName: String • domain-specific name BlockSpeedLimit: Speed • enumeration GoSignal: {on, off} Keywords: Topics Attributes (2) Elementary attribute: sort is a set of atomic values – e.g. DoorsState: {open, closed} Structured attribute: sort defined with type constructor – Tuple, SetOf, SequenceOf, Union – e.g. Keywords: SetOf [Topic] , dateRange: SeqOf [Date] Precise, domain-specific semantics of attribute must be defined in Has annotations Attribute multiplicity: min/max number of values the attribute may take [0..x]: optional attribute [x..*]: attribute value = set of values [1..1]: mandatory attribute, single value: by default, omitted e.g. PhoneNr [0..*]: String optional, possibly multiple values Entities, associations, attributes in UML Command * Driving attribute Car In CommandedSpeed: Speed CommandedAccel : Acceleration 1 Train 0..1 isOn CurrentSpeed: Speed CurrentLoc: Location DoorsState: {open,...} * On 0..1 holdsTrain Block SpeedLimit: Speed At Platform 0..1 ... Entities, agents, associations, attributes in UML attribute of association Loan DateBorrowed: Date TimeLimit: NumberWeeks DueReturnDate: Date Patron 0..1 Borrows 0..Max BookCopy BorrowedBy CopyID Phone [*] : String Period * Library Copy 1 Book Keywords [1..*] : Topics Registration DateRegistered: Date Deposit: Money attribute of association multiplicity Modeling conceptual objects What is a conceptual object? Entities BookCopy Associations & multiplicities Patron Attributes Patron Name Specialization StudentPatron Loan BookCopy Patron StaffPatron Aggregation More on class diagrams Building object models: heuristic rules Library BookCopy Built-in associations for structuring object models Object specialization/generalization, decomposition/aggregation – applicable to entities, agents, events, associations Specialization = subclassing: object SubOb is a specialization of object SuperOb iff for any individual o: InstanceOf (o, SubOb) InstanceOf (o, SuperOb) • SubOb specializes SuperOb, SuperOb generalizes SubOb • amounts to set inclusion on set of current instances Feature inheritance as a consequence ... – by default, SubOb inherits from SuperOb all its attributes, associations, domain properties • while have its own distinguishing features – may be inhibited by compatible redefinition of feature with same name within specialized SubOb (“override”) Object specialization with inheritance Command * Driving Car CommandedSpeed: Speed CommandedAccel : Acceleration 1 Train In 0..1 isOn CurrentSpeed: Speed CurrentLoc: Location DoorsState: {open,...} specialisation Semi-rapid * On 0..1 holdsTrain SpeedLimit: Speed At inherited features 0..1 Rapid Block Platform ... Inhibiting inheritance TrafficSignal ... inherited Color: {green, orange, red} Location WarningSignal compatible redefinition (subsort) Color: {orange} The more specific feature always overrides the more general one Multiple inheritance Same object may be specialization of multiple super-objects – by default, inheritance of all features from all super-objects Can result in inheritance conflicts – different features with same name inherited from different super-objects => conflicting features first renamed to avoid this renamed StudentAddress to avoid conflict Patron Address Email Student Address StudentID StudentPatron ... Multiple specializations Same object may have multiple specializations – Different subsets of object instances associated with different criteria – Same object instance may be member of different subsets (one per criterion) Discriminator = attribute of super-object whose values define different specializations (differentiation criterion) Tra in d iscrim in a ting a ttrib u te Ac c eler ation Door s State Speed S e m iR ap id … Capac ity R a p id … S h o rtTra in … L o n g Train … Object generalization Loan featur es inher i ted by all s pecia liz ations DateBor r ow ed: D ate Ti meLi mit: N um b erW eek s … r egis ter edAt P a tro n 0..1 0..Max Bor r owedBy Phone [*]: Str i ng Emai l: Pr efi x x Suffix Bor r ows m ultiple inher itanc e S tu d e n tP a tro n … S tu d e n t StudentID … Y ear Of Study S ta ffP a tro n Depar tment B o rro w ab le Item Copy ID Date Enter ed B o o kC op y Jo u rn alC op y … … P ro ce e din gsC o p y Res ear c hAcc ount P ro cO f Copy … Book A uthor Jo u rn al Is s ue C o n fe ren ce Conf Ser ies generalization is not necessarily apparent in problem world Benefits of generalization-based structuring Common features in multiple objects are factored out into single generalized object => simpler model, no duplication Generalized objects & their structure are reusable in different contexts & systems (by specialization) – e.g. BorrowableItem --> CDCopy , VideoCopy Increased modifiability of large models – modifications of more general features are localized in more general objects, down-propagated to specialized objects StudentPatron NonPriviledgedPatron Patron Object aggregation Aggregation = composite object whose components are objects (“parts”) InstanceOf (ob, AggrOb) ob = Tuple (o1, ..., on) with InstanceOf (oi , PartObi ) – applicable to entities, agents, events, associations – multiplicities may be attached to part-to-aggregation links – transitive, antisymmetrical links Composition: aggregation & parts appear/disappear together ob = Tuple (o1, ..., on) and not InstanceOf (ob, AggrOb) not InstanceOf (oi , PartObi ) – part object may then be part of one aggregation object only Object aggregation: examples L ib ra ry Tra in … aggr egation … At P la tfo rm … In 0..1 1..* 1 D ire cto ry S h e lve An tiTh e ft Car … … … … com pos ition 2 Door Th e ftS e n so r … Th e ftAla rm … … More on UML class diagrams Derived attribute, association = defined in terms of other attrib/assoc already in the model – controlled form of redundancy Loan derived attribute DateBorrowed: Date TimeLimit: NumberWeeks / DueReturnDate: Date derived association Door 1..2 Car In Train On At / DoorsOf Block Platform More on UML class diagrams (2) OR association = same role played by alternative objects – set of object instances in this role = union of alternative sets of object instances O R-as s ociation M as terO f Book 0..1 … B o rro w ab le Item Copy ID Date Enter ed * * Copy Copy 0..1 M as terO f Jo u rn al … More on UML class diagrams (3) Ordered association: multiple target instances from source instance (or tuple of instances) are ordered Library 1 1..* 1 Directory Shelve 0..1 (ordered) BookCopy CopyID * Content 0..1 AntiTheft More on UML class diagrams (4) Association of associations: one of the linked objects is an association S eason … 1 .. * C o n c e rt 1 1 H a ll … … P e rfo rm a n ce D a te 1 .. * R e s e rva tio n 1 .. * R e s e rv# R e s e rvD a te Seat S e a t# Modeling conceptual objects What is a conceptual object? Entities BookCopy Associations & multiplicities Patron Attributes Patron Name Specialization StudentPatron Loan BookCopy Patron StaffPatron Aggregation More on class diagrams Building object models: heuristic rules Library BookCopy Building object models: heuristic rules Deriving pertinent & complete object models from goal models – deriving objects, associations, attributes – introducing software-environment tracking associations – identifying associations from domain invariants on multiple objects Object or attribute ? Entity, association, agent, or event ? Attribute of a linked object or of a linking association ? Aggregation or association ? Specializing, generalizing concepts Bad smells Deriving objects, associations, attributes from the goal model F Review all specs of goals & domain properties in goal model ... – take all referenced concepts meeting criteria for object, and only those • instances distinctly identifiable, enumerable in any state, sharing similar features, differing in individual states – consider the others as candidate qualifying attributes • values are NOT concept instances to be characterized by common attributes, associations – identify associations + participating objects from linking expressions in these specs <sourceObj> <linkingVerb> <targetObj(s)> <linkingNoun> of <targetObj> by <sourceObj> Deriving objects, associations, attributes from goal specs: example Goal Maintain [BlockSpeedLimited] Def The speed of a train on a block may never exceed the limit associated with that block Train Speed: SpeedUnit ... On Block SpeedLimit: SpeedUnit ... Rephrasing sometimes needed to highlight linking expressions Yet another reason for goal specs to be precise ! Deriving objects, associations, attributes from goal specs: example (2) Goal Maintain [WorstCaseStoppingDistance] Def The distance between two trains following each other shall be sufficient to prevent the back train from hitting the front train in case the latter stops suddenly Following back Train front Speed: SpeedUnit WCS-Dist: Distance On Block SpeedLimit: SpeedUnit ... Introducing software-environment tracking associations F For goal assignment to software-to-be, we must introduce shared “images” of environment objects referenced by the goal – the shared object tracking its environment counterpart must accurately reflect it (=> new accuracy goal) – e.g. TrainInfo (Speed, Position) tracking Train (Speed, Position) LoanInfo tracking Loan, PatronInfo tracking Patron – cf. goal refinement pattern seen before: GoalOnUnMonitorableCondition GoalOnUnControllableCondition GoalOnMonitorable Condition MonitorableCondition Iff UnMonitorableCondition GoalOnControllable Condition ControllableCondition Iff UnControllableCondition Introducing software-environment tracking associations: a general pattern Goal on environment Object Goal onObj-Info Software-to-be Object Accurately Tracked By Obj-Info tracks Obj-Info Object trackedBy 1 Tracking 1 … Att: Range Refers to Att: Range Identifying associations from domain invariants on multiple objects Domain properties in goal refinements are to be defined in annotations of the object model (as seen before) – invariants on single objects they constrain Invariant seeming to constrain multiple objects ... ? => ? constrains missing association among these ? – e.g. “A platform cannot accommodate more than one train at a time” ... constrains platforms ? ... or trains ? => to be attached to missing association At linking Train and Platform Derivation links between goal model & object model are bidirectional From goals to objects ... – as just seen From objects to goals ... – Domain concepts that should “obviously” appear in object model ... WHY? => missing goals in goal model – Systematic association decoration with multiplicities ... prescriptive? => missing goals in goal model WHY? => parent goals HOW? => subgoals Object or attribute ? F For X: conceptual item in goal specs, make X an attribute if... – X is a function: yielding one single value (possibly structured) when applied to conceptual instance – instances of X need not be distinguished – you don’t want to attach attributes/associations to X, specialize it, or aggregate/decompose it – its range is not a concept you want to specialize or attach attributes/associations Book Authors: String Writing Author vs. Birthdate MainAuthor Co-Author Book Entity, association, agent, or event ? F For X: conceptual object in goal specs ... – instances of X are defined in one single state event e.g. StartTrain – instances of X are active: control behaviors of other object instances agent e.g. DoorsActuator – instances of X are passive, autonomous entity e.g. Train – instances of X are passive, dependent on other, linked object instances association e.g. Following (Train, Train) F N-ary if each of the N parties ... - need be considered as objects - yields tuples to be distinguished Attribute of a linked object or of a linking association ? Ob1 X? 0.. 0.. Ob1 X? Assoc X? F Attach attribute to association if it explicitly or implicitly characterizes all participating objects – esp. if possibly no instance currently in some role, to avoid losing info – e.g. who did borrow this book copy? Borrower 0..1 0..Max BookCopy DateBorrowed Loan DateBorrowed Aggregation or association ? F For X a structural link between "composite" & "component" objects, make it an association if any of these holds ... – X has a domain-specific InstanceOf semantics – component & composite objects seem independent • component not subordinate to composite as in composition – attributes or associations need be attached to the link type – in case of doubt e.g. In (Car, Train) Specializing, generalizing concepts F Identify specializations from classification expressions & discriminant factors in goal/domprop specs – taxonomical keywords “types of”, “kinds of”, “category”, “class”, ... – meet object criteria ? – relevant commonalities to factor out, specifics to discriminate ? – multiple classifications under discriminating attributes ? F Identify generalizations from objects characterized by similar attributes, associations, domain invariants – bottom-up search for common abstractions, not necessarily visible – if worth doing so, without cluttering the model StationBlock Block Corridor N Building object models: bad smells F Avoid “pointers” to other objects as attributes – use binary associations insead BAD BookCopy Borrower Loan: BookCopy GOOD Borrower Loan BookCopy N Building object models: bad smells (2) F Avoid non-structural links pertaining to other views – monitoring/control links from agent model (context diagram) TrainController setsAcceleration getsPosition TrackingSystem Initiator setsDateRange Meeting Scheduler setsDate BAD Train Train BAD GOOD BAD Initiator Initiating Meeting DateRange Date Scheduler Scheduling N Building object models: bad smells (3) F Avoid non-structural links pertaining to other views – dynamic links from behavior model (state diagram) BAD BorrowerRequest Generates Loan BAD GoSignal Activates Train N Building object models: bad smells (4) F Avoid obscure names for objects & attributes – suggestive shortcut of their annotated definition • don’t forget precise definition! • don’t confuse terms ! e.g. Book vs. BookCopy – from problem world, NOT implementation-oriented Bad JPEG_File , Book_File Good Picture , Directory – specific, NOT vague Bad Person , Form Good Patron , RegistrationForm – commonly used, NOT invented Bad PersonalIdentificationCard, ConferenceBook Good StudentCard, Proceedings