Lecture 3 ANALYSIS AND DESIGN PB007 Software Engineering I Faculty of Informatics, Masaryk University Fall 2017 1© Barbora Bühnová Outline ² Software analysis and design ² Structured vs. object-oriented methods ² Object-oriented analysis in UML ² Objects and classes ² Finding analysis classes 2Chapter 7 Design and implementation Software Analysis and Design Lecture 3/Part 1 3Chapter 7 Design and implementation Analysis, design and implementation ² Software development § analysis, design and implementation § the stage in the software engineering process at which an executable software system is developed “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare 4Chapter 7 Design and implementation PROBLEM Requirements System SOLUTION Analysis Design Implementation Analysis, design and implementation ² Software analysis, design and implementation are invariably inter-leaved with blurred border in between. § Software analysis is a creative activity in which you identify software processes, entities (objects) and their relationships. § Software design refines analytical models with implementation details. § Implementation is the process of realizing the design as a program. ² Where is the line between the problem domain and the solution domain? ² Why do we distinguish them when the line is blurred anyway? 5Chapter 7 Design and implementation PROBLEM Requirements System SOLUTION Analysis Design Implementation Process stages ² There is a variety of different design processes that depend on the organization using the process. ² Common activities in these processes include: 1. Define the context and modes of use of the system; 2. Draft the system architecture; 3. Identify the principal system processes and entities; 4. Develop design models; 5. Specify component/object interfaces; 6. Finalize system architecture. ² What activities are part of analysis/design/implementation? 6Chapter 7 Design and implementation 1. System context and interactions ² Understanding the relationships between the software and its external environment is essential for deciding § how to provide the required system functionality and § how to structure the system to communicate with its environment. ² Understanding of the context also lets you establish the boundaries of the system. § Setting the system boundaries helps you decide what features are implemented in the system being designed and what features are in other associated systems. 7Chapter 7 Design and implementation Context and interaction models ² A system context model is a structural model that demonstrates the users and other systems in the environment of the system being developed. ² An interaction model is a dynamic model that shows how the system interacts with its environment as it is used. ² Do we really need visual models for that? What is their role in A&D? 8Chapter 7 Design and implementation 2. Architectural design ² Starts system analysis and/or finishes system design. § Is it the same architecture design in both cases? ² Involves identifying major system components and their communications. § Represents the link between requirements specification and analysis/design processes. § E.g. The weather station is composed of independent subsystems that communicate via (asynchronous) messaging. ² Software architecture gives answers to the most expensive questions. – heard from O. Krajíček 9Chapter 6 Architectural design High-level architecture of the weather station 10Chapter 7 Design and implementation Architectural abstraction ² Architecture in the small (analysis) is concerned with the architecture of individual programs. § At this level, we are concerned with the way that an individual program is decomposed into components. ² Architecture in the large (design) is concerned with the architecture of complex enterprise systems that include other systems, programs, and program components. § These systems are distributed over different computers, which may be owned and managed by different companies. 11Chapter 6 Architectural design Advantages of explicit architecture ² Stakeholder communication and project planning § Architecture may be used to facilitate the discussion by system stakeholders. ² System analysis § Means that analysis of whether the system can meet its nonfunctional requirements is possible. ² System documentation § Via a complete system model that shows the different components in a system, their interfaces and their connections. ² Large-scale reuse § The architecture may be reusable across a range of systems § Product-line architectures may be developed. 12Chapter 6 Architectural design 3. System analysis ² Identification of system entities (object classes in object-oriented analysis) playing the key roles in the system’s problem domain, and their relationships. ² Distillation and documentation of key system processes. ² System analysis is a difficult creative activity. § There is no 'magic formula' for good analysis. It relies on the skill, experience and domain knowledge of system analysts. ² Object/relationships/processes identification is an iterative process. You are unlikely to get it right first time. 13Chapter 7 Design and implementation Weather station object classes 14Chapter 7 Design and implementation 5. Design models ² Design models refine analysis models with the information required to communicate and document the intended implementation of the system. § E.g. Dependencies, interfaces, data-access classes, GUI classes. ² Static models describe the static structure of the system in terms of system entities and relationships. § Can you list some static UML diagrams? ² Dynamic models describe the dynamic interactions between entities. § Can you list some dynamic UML diagrams? 15Chapter 7 Design and implementation Key points ² The process of analysis and design includes activities to design the system architecture, identify entities in the system, describe the design using different models and document the component interfaces. ² Software analysis is a creative activity in which you identify software processes, entities (objects) and their relationships. ² Software design refines analytical models with implementation details. ² Software analysis and design are inter-leaved activities. 16Chapter 7 Design and implementation Structured vs. Object-Oriented Methods Lecture 3/Part 2 17 © Strukturovaná analýza systémů by J. Ráček Fundamental views of software systems ² Function oriented view § System as a set of interacting functions. Functional transformations based in processes, interconnected with data and control flows. ² Data oriented view § Searches for fundamental data structures in the system. Functional aspect of the system (i.e. data transformation) is less significant. ² Object oriented view § System as a set of interacting objects, encapsulating both the data and operations performed on the data. 18 © Strukturovaná analýza systémů by J. Ráček Structured vs. object-oriented analysis ² Structured analysis § Driven by the function oriented view, in synergy with data oriented view, through the concept of functional decomposition. ² Object-oriented analysis § Driven by the object oriented view. Do they have anything in common? 19 © Strukturovaná analýza systémů by J. Ráček Structured analysis and design ² Divides a project on small, well defined activities and defines the order and interaction of the activities. ² Using hierarchical graphical techniques, resulting in a detailed structured specification, which can be understood by both system engineers and users. ² Effective in project structuring to smaller parts, which simplifies time and effort estimates, deliverables control and project management as such. ² Aimed at increasing system quality. 20 © Strukturovaná analýza systémů by J. Ráček Functional decomposition 21 System context Level 0 processes Level 1 processes Data dictionary Basic-process specification © Strukturovaná analýza systémů by J. Ráček Structured methods ² DeMarco: Structured Analysis and System Specification (SASS) ² Gane-Sarson: Logical Modelling (LM) ² Yourdon: Modern Structured Analysis (YMSA) § Concentrates on the data and control flow of system processes and sub-processes. ² Structured Systems Analysis and Design Method (SSADM) § Physical design, logical process design and logical data design 22 © Strukturovaná analýza systémů by J. Ráček Core notations of structured methods ² Context diagram § Models system boundary and environment. ² Data flow diagram (DFD) § Models the system as a network of processes completing designated functions and accessing system data. ² Entity relationship diagram (ERD) § Models system’s data. ² State diagram (STD) § Models system states and actions guarding transitions from one state to another. 23 © Strukturovaná analýza systémů by J. Ráček Examplary method (Gane-Sarson) 1. Define system context and create initial system DFD. 2. Draft initial data model (ERD). 3. Analyze data entities and relationships into final ERD. 4. Refine DFD according to the ERD data model (create logical process model). 5. Decompose logical process model into procedural elements. 6. Specify the details of each individual procedural element. 24 © Strukturovaná analýza systémů by J. Ráček Object-oriented analysis and design ² Software engineering approach that models a system as a group of interacting objects. ² Each object represents some entity of interest in the system being modeled, and is characterized by its class, its state (data elements), and its behavior. ² Various models can be created to show the static structure, dynamic behavior, and run-time deployment of these collaborating objects. ² There is a number of different methods, defining the ordering of modeling activities. The modeling notation uses to be unified (UML). 25Chapter 7 Design and implementation Object-oriented methods ² Jim Rumbaugh: Object Modelling Technique (OMT) ² Coad-Yourdon: Method for Object-Oriented Analysis (OOA) ² Jacobson: Object-Oriented Software Engineering (OOSE) ² Kruchten et al.: Rational Unified Process (RUP) § Risk-driven iterations, component-based, with continuous quality verification and change management. ² Booch-Jacobson-Rumbaugh: Unified Process (UP) § Simplified non-commercial version of RUP maintained by Object Management Group (OMG). 26Chapter 7 Design and implementation UML notation for object-oriented methods ² External perspective § Use case diagram ² Structural perspective § Class diagram, Object diagram, Component diagram, Package diagram, Deployment diagram, Composite structure diagram ² Interaction perspective § Sequence diagram, Communication diagram, Interaction overview diagram, Timing diagram ² Behavioral perspective § Activity diagram, State diagram 27Chapter 7 Design and implementation Examplary method (Unified Process, analysis and design excerpt) 1. Requirements § System boundary, actors and requirements modelling with Use Case diagram. 2. Analysis § Identification of analysis classes, relationships, inheritance and polymorphism, and their documentation with a Class diagram. § Use Case realization with Interaction and Activity diagrams. 3. Design § Design classes, interfaces and components, resulting in refined Class diagrams and Component diagrams. § Detailed Use Case realization with Interaction and State diagrams. 28Chapter 7 Design and implementation Key points 29 © Strukturovaná analýza systémů by J. Ráček Structured analysis Object-oriented analysis System boundary Context diagram Use case diagram Functionality Data flow diagram Activity diagram Interaction diagrams Data Entity-relationship diagram Class and Object diagram Control State diagram State diagram ² Structured methods § System as a set of nested processes accessing system data. ² Object-oriented methods § System as a set of interacting objects (functions and data). Object-Oriented Analysis in UML Lecture 3/Part 3 30© Clear View Training 2010 v2.6 © Clear View Training 2010 v2.6 31 Analysis objects and classes What are objects? ² Objects consist of data and function packaged together in a reusable unit. Objects encapsulate data. ² Every object is an instance of some class which defines the common set of features (attributes and operations) shared by all of its instances. ² Objects have: § Attribute values – the data part § Operations – the behaviour part number = "1243" owner = "Jim Erl" balance = 300 deposit() withdraw() getOwner() setOwner() Bank Account Object attribute values operations © Clear View Training 2010 v2.6 32 All objects have ² Identity: Each object has its own unique identity and can be accessed by a unique handle § Distinguish two cars of the same type and one car referenced from two places. ² State: This is the actual data values stored in an object at any point in time § On and off for a light bulb (one attribute). § On + busy, on + idle, off for a printer (two attributes). ² Behaviour: The set of operations that an object can perform © Clear View Training 2010 v2.6 33 Messaging ² In OO systems, objects send messages to each other over links ² These messages cause an object to invoke an operation Bank Object Account Object withdraw( 150.00 ) the Bank object sends the message “withdraw 150.00” to an Account object. the Account object responds by invoking its withdraw operation. This operation decrements the account balance by 150.00. message © Clear View Training 2010 v2.6 34 UML Object Syntax ² All objects of a particular class have the same set of operations. They are not shown on the object diagram, they are shown on the class diagram (see later) ² Attribute types are often omitted to simplify the diagram ² Naming: object and attribute names in lowerCamelCase, class names in UpperCamelCase jimsAccount : Account accountNumber : String = "1234567" owner : String = "Jim Arlow" balance : double = 300.00 attribute name attribute compartment name compartment attribute type attribute value object name class name jimsAccount : Account jimsAccount : Account object and class name object name only class name only variants (N.B. we've omitted the attribute compartment) an anonymous object object identifier (must be underlined) © Clear View Training 2010 v2.6 35 What are classes? ² Every object is an instance of one class - the class describes the "type" of the object ² Classes allow us to model sets of objects that have the same set of features - a class acts as a template for objects: § The class determines the structure (set of features) of all objects of that class § All objects of a class must have the same set of operations, must have the same attributes, but may have different attribute values ² Classification is one of the most important ways we have of organising our view of the world ² Think of classes as being like: § Rubber stamps § Cookie cutters class object © Clear View Training 2010 v2.6 36 Exercise - how many classes? © Clear View Training 2010 v2.6 37 Classes and objects ² Objects are instances of classes. ² Instantiation is the creation of new instances of model elements. ² Most classes provide special operations called constructors to create instances of that class. ² These operations have class-scope i.e. they belong to the class itself rather than to objects of the classs. withdraw() deposit() Account accountNumber : String owner : String balance : double objects class ilasAccount:Account accountNumber : "803" owner : "Ila" balance : 310.00 fabsAccount:Account accountNumber : "802" owner : "Fab" balance : 1000.00 JimsAccount:Account accountNumber : "801" owner : "Jim" balance : 300.00 «instantiate»«instantiate» «instantiate» © Clear View Training 2010 v2.6 38 UML class notation ² Classes are named in UpperCamelCase – avoid abbreviations! ² Use descriptive names that are nouns or noun phrases Window +size : Area = (100,100) #visibility : Boolean = false -colorRGB : Integer [3] -defaultSize : Rectangle -maximumSize : Rectangle -xptr : XWindow* +create() +hide() +display( location : Point ) -attachXWindow( xwin : XWindow*) {author = Jim, status = tested} name compartment attribute compartment operation compartment class name tagged values initial values class scope (static) operation visibility adornment Window size : Area visibility : Boolean hide() display() Analytical class Design class © Clear View Training 2010 v2.6 39 Attribute compartment Structure visibility name : type multiplicity = initialValue Visibility + public - private # protected ~ package Type Integer, Real, Boolean, String, Class Multiplicity [3] specific number of elements [0..1] optional * array, list Initial values Window +size : Area = (100,100) #visibility : Boolean = false -colorRGB : Integer [3] -defaultSize : Rectangle -maximumSize : Rectangle -xptr : XWindow* +create() +hide() +display( location : Point ) -attachXWindow( xwin : XWindow*) {author = Jim, status = tested} mandatory attribute compartment Operation signature visibility name ( direction parameterName : parameterType = default, ...) : returnType Direction in input value, default out repository for system output inout modifiable input value return operation return value(s) Scope instance scope defaults class scope underlined Constructors generic constructor name or Java/C++ standard +BankAccount( aNumber : int ) © Clear View Training 2010 v2.6 40 Operation compartment parameter list or a list r1, r2,… rn BankAccount -accountNumber : int -count : int = 0 +create( aNumber : int) +getNumber() : int -incrementCount() +getCount() : int operation compartment © Clear View Training 2010 v2.6 41 Key points ² We have looked at objects and classes and examined the relationship between them ² We have explored the UML syntax for modelling classes including: § Attributes § Operations ² We have seen that scope controls access § Class scope attributes are shared by all objects of the class and are useful as counters § Attributes and operations are normally instance scope § We can use class scope operations for constructor and destructors Finding Analysis Classes Lecture 3/Part 4 42© Clear View Training 2010 v2.6 © Clear View Training 2010 v2.6 43 What are Analysis classes? ² Analysis classes represent a crisp abstraction in the problem domain § They may ultimately be refined into one or more design classes ² Analysis classes have: § A very “high level” set of attributes. They indicate the attributes that the design classes might have. § Operations that specify at a high level the key services that the class must offer. In Design, they will become actual, implementable, operations. BankAccount name : String address balance : double deposit() withdraw() calculateInterest() class name attributes operations Specify attribute types if you know what they are. © Clear View Training 2010 v2.6 44 What makes a good analysis class? ² Its name reflects its intent ² It is a crisp abstraction that models one specific element of the problem domain § It maps onto a clearly identifiable feature of the problem domain ² It has high cohesion § Cohesion is the degree to which a class models a single abstraction § Cohesion is the degree to which the responsibilities of the class are semantically related ² It has low coupling § Coupling is the degree to which one class depends on others © Clear View Training 2010 v2.6 45 Rules of thumb ² 3 to 5 operations per class ² Each class collaborates with others ² Beware many very small classes ² Beware few but very large classes ² Beware of “functoids” ² Beware of “omnipotent” classes ² Avoid deep inheritance trees A responsibility is a contract or obligation of a class - it resolves into operations and attributes © Clear View Training 2010 v2.6 46 ² Perform noun/verb analysis on documents: § Nouns are candidate classes § Verbs are candidate responsibilities What documents can be studied? ² Perform CRC card analysis § Class, Responsibilities and Collaborators § A two phase brainstorming technique using sticky notes – first brainstorm and then analyse the dat Finding classes Responsibilities: Class Name: BankAccount Collaborators: Maintain balance Bankthings the class does things the class works with © Clear View Training 2010 v2.6 47 Other sources of classes ² Physical objects ² Paperwork, forms § Be careful when relying on processes that need to change ² Known interfaces to the outside world ² Conceptual entities that form a cohesive abstraction ² With all techniques, beware of spurious classes § Look for synonyms - different words that mean the same § Look for homonyms - the same word meaning different things © Clear View Training 2010 v2.6 48 Key points ² We’ve looked at what constitutes a well-formed analysis class ² We have looked at two analysis techniques for finding analysis classes: § Noun verb analysis of use cases, requirements, glossary and other relevant documentation § CRC analysis