2.14k likes | 2.39k Views
Engineering. RW344 : Software Design. ▬ ▬ ▬. Bernd Fischer bfischer@cs.sun.ac.za. Modeling and Design. Topics. UML class diagrams sequence diagrams communication diagrams design principles software architecture design patterns. Development.
E N D
Engineering RW344: Software Design ▬▬▬ Bernd Fischer bfischer@cs.sun.ac.za
Topics • UML • class diagrams • sequence diagrams • communication diagrams • design principles • software architecture • design patterns
Development Main concern: how should the system work? development: converting the system specification into an executable system
Development=Design+Implementation Traditionally broken down into several stages: • architectural design • component design • interface design • data structure design • abstract specification • algorithm design • coding • debugging • development is an iterative process with feedback between the stages • design and implementation are typically interleaved development: converting the system specification into an executable system
Design vs.Modeling • guided by design principles • part of development • uses modeling languages • spans requirements and development Designis the process of deciding how the requirementsshould be implemented. Modelingis the process of creating an abstractrepresentation of the domainor the system.
UML (Unified Modeling Language) • graphicalmodeling language • standardized by OMG (Object Management Group) • semi-formal • variety of different diagram types • supports object-oriented designs • but no fixed methodology • unified: each diagram gives a different view on the same system • developed by Rumbaugh, Booch, Jacobson et al. • starting early-90’s, unification mid-90’s
Structural vs. behavioralmodeling • class diagrams • System = structure + behavior • structural models show the system’s organization in terms of its components and their relationships • can be static (classes) or dynamic (threads) • behavioral models show the system’s dynamic as it is executing and responding to stimuli • can be eventsor data
Class diagram essentials Main elements: • classes: represent the types of the data • attributes: represent the data found in instances • associations: show how instances are related • generalizations: represent inheritance hierarchies • operations: represent the actions by instances Class diagramsdescribe the datafound in a software system.
Classes A class describes a collection of instances with common properties and similar behavior. • classname • noun phrase, head singular and countable, PascalCase • attributes • noun phrase, singular, camelCase(verb phrase if Boolean) • operations • verb phrase, camelCase More information: • D. Aguilera, C. Gómez, A.Olivé: A complete set of guidelines for naming UML conceptual schema elements. Data Knowl. Eng. 88: 60-74 (2013).
Classes A class describes a collection of instances with common properties and similar behavior. attributes andoperationscan have additional visibility and type information
Classes A class describes a collection of instances with common properties and similar behavior. attributes andoperationsare optional
Associations An association describes how instances(of two classes) referenceeach other. • associationname • verb phrase, camelCase • reading order • <left entity> <association> <right entity>
Multiplicities Multiplicities describe how many instances(of the two classes) are related by an association. • “many” • “optional” . • Symbol at an association end indicates how many instances of this end are related to one instance on the other end
Multiplicities Multiplicities describe how many instances(of the two classes) are related by an association. • “non-empty” • NOTE: multiplicities carry a lot of meaning, so they should always be given. .
Multiplicities Multiplicities describe how many instances(of the two classes) are related by an association. • “non-empty” • NOTE: multiplicities are difficult to get right, so always read them in both directions. .
Typical multiplicities • one-to-many: common, strictly hierarchical relations • many-to-many: common, matrix relations • one-to-one: often abused
Typical multiplicities • one-to-many: common, strictly hierarchical relations • many-to-many: common, matrix relations • one-to-one: often abused • better to model class by additional attributes
Exercises Model with appropriate multiplicities: • docents teaching courses taken by students • musicians planning performances of different plays at different venues
Named association ends • association ends can be named (role names) • associations can be reflexive • role name
Association directionality • associations are normally bi-directional: • for each Order, we know Items it contains • for each Item, we know which Order it belongs to • association direction can be restricted (navigable): • can only go from Order to Item • ... but not vice versa • NOTE: directionality limits implementation freedom! • Use it sparingly, add it later.
Association classes • some attributes can be difficult to allocate to classes: • where should grade go? • use association class: • association name disappears • each Student-Class link contains an object of type Registration
Association classes can be eliminated. • replace association + association class by two (one-to-many) associations: • couldn’t get this working in Astah...
Aggregation Use when • the parts are partOf the aggregate(or the aggregate isComposedOf the parts) • whoever owns or controls the aggregate, also owns or control the parts Aggregations represent part-whole associations between instances. • aggregateclass • implicit partOf association
Aggregation hierarchies • aggregation can be arranged hierarchically • NOTE: not the same as inheritance • typicallyone-to-many
Composite associations Use when • the part cannot exist without the whole aggregate Composite associations representstrongpart-whole associations between instances. • compositeclass • must be “1”
Composite associations vs. attributes • one-to-one composite associations can also bemodeled as attributes (and vice versa)
Exercises Which mechanism (association, aggregation, or composition) should be used to model the following relations: • telephone and handset • school and teachers • book and chapters • country and provinces • polygon and lines
Generalization Inheritance must obey the isa rule: • “a <subclass> is a <superclass>” must make sense! Generalization represents inheritance hierarchies. This a relation on classes, not an association between instances!
Generalization Stereotypes: • <<complete>> indicates that the superclass is abstract (i.e., instances exist only in the subclasses) • <<disjoint>> indicates that each instance can only be instance of one class(opposite: <<overlapping>>) <<disjoint>> <<complete>>
Generalization • use a discriminator label to denote the criterion used to distinguish different subclasses • in particular for disjoint generalization
Pitfalls – multiple generalization • UML allows multiple inheritance • but Java doesn’t... • and there are problems with repeated attributes
Pitfalls – overgeneralization • no difference other than discriminator label • better solution: • object diagram
Pitfalls – class change • instances should never change their class!
Interfaces • similar to classes, except they lack instance variables and implemented methods An interface describes a portion of the visible behaviour of a set of objects.
Classdiagramscanbeusedtomodelthe problematdifferentlevelsofabstraction. • domain model • developed in domain analysis to understand the domain • models also aspects of the domain that will not be implemented by the system • also called exploratory domain model • system domain model • models only aspects of the domain that are implemented by the system • system model • models also classes outside the domain but usedto build the user interface and system architecture shrink &refine grow &refine
Domain class model The domain class model contains: • relevant entities as classes: • physical objects • persons, organizations (actors) • events, processes, abstractions • links between entities as associations: • relations • communications • part/whole relations (aggregation, composition)
Domain class model The domain class model should only use a limited set of notations (“boxes and arrows”): • classes • use attributes sparingly • associations with multiplicities • use aggregation and composition sparingly • generalization It should not use: • methods • types • roles
Arecipetocookdomainclassmodels... boxes • add classes (without attributes) • identify relevant real system objekts and represent as classes • add generalizations • add associations (with multiplicities) • identify relations between identifed objects • add aggregations and compositions • check whether really necessary • add attributes (no operations) • identify relevante core attributes and add to corresponding classes • stir until done arrows
Discovering domain classes Noun phrase analysis: • analyze (textual) documents describing the system • use cases • requirements documents • extract the nouns and noun phrases • eliminate nouns that • are redundant, vague, or highly general • are too specific or represent specific instances • refer to the entire system or objects outside the application • pay attention to nouns that describe different user types or other actors
Discovering associations • start with central and most important classes • work outwards towards the less important classes • add an association if one class • possesses or controls • is related to • communicates with • is a part of • is a member of some other class in the model • label it clearly • specify the multiplicity at both ends • KISS: keep it simple • Don’t rely on verb phrases – associations are often left implicit!
Pitfalls – transient associations • an association is only legitimate if the links “survive” beyond execution of an operation • links are stored in database • if nothing needs to be stored, rethink the association • What do you store??
Pitfalls – actions as associations • actions should not be modelled as associations but as association classes • store information associated with action • different operations access different attributes
Pitfalls – actions as associations • actions should not be modelled as associations but as association classes • store information associated with action • different operations access different attributes
Pitfalls – actions as associations • actions should not be modelled as associations but as association classes • store information associated with action • different operations access different attributes