# 軟體工程 --- :::info [TOC] ::: --- # Chapter5 System modeling ## System modeling - The process of developing abstract models(抽象模型) of a system. - Each model presenting a different view or perspective(角度) of that system. - mean representing a system using some kind of graphical notation(UML). - helps the analyst to understand the functionality of the system and models are used to communicate with customers. ### Existing and planned system models - Models of the existing system are used during [**requirements engineering**](https://zh.m.wikipedia.org/zh-tw/%E9%9C%80%E6%B1%82%E5%B7%A5%E7%A8%8B) - help clarify what the existing system does and can be used as a basis for discussing its strengths and weaknesses. - Models of the new system are used during requirements engineering to help explain the proposed requirements to other system stakeholders(利益關係人). - In a **model-driven** engineering process, it is possible to generate a **complete** or **partial** system **implementation** from the system model. #### System perspectives(系統觀點) - An **external** perspective - where you model the context or environment of the system. - An **interaction** perspective - where you model the interactions between a **system** and its **environment**, or between the **components** of a system. - A **structural** perspective - where you model the **organization of a system** or the **structure of the data** that is processed by the system. - A **behavioral** perspective - where you model the **dynamic behavior** of the system and how it **responds to events**. ### The Unified Modeling Language - UML is a set of 13 different diagram types. - It emerged from work in the 1990s on object-oriented modeling, where similar object-oriented notations were integrated to create the UML. #### UML diagram types 1. Activity diagrams - which show the activities involved in a process or in data processing. 2. Use case diagrams - which show the interactions between a system and its environment. 3. Sequence diagrams - which show interactions between actors and the system and between system components. 4. Class diagrams - which show the object classes in the system and the associations between these classes. 5. State diagrams - which show how the system reacts to internal and external events. ### Use of graphical models - As a means of facilitating discussion(促進討論) about an existing or proposed system - Incomplete and incorrect models are OK as their role is to support discussion(支持討論). - As a way of documenting(紀錄) an existing system - Models should be an accurate representation of the system but need not be complete. - As a detailed system description that can be used to generate a system implementation(實作) - Models have to be both correct and complete. ## Context(環境) Models - Context models are used to illustrate the operational context of a system - they show what lies outside the **system boundaries** - Social and organizational concerns may affect the decision on where to position system boundaries - **Architectural models(架構)** show the system and its relationship with other systems. ### System boundaries - System boundaries are established to define what is inside and what is outside the system - The position of the system boundary has a profound(強烈的) effect on the system requirements - Defining a system boundary is a political(有爭議性的) judgment ### Ex : The context of the Mentcare system ![](https://i.imgur.com/k3uj3gW.png) ## Process perspective - **Process models** reveal how the system being developed is used in broader business processes. - UML ==activity diagrams== may be used to define business process models. ### EX: Process model of involuntary detention ![](https://i.imgur.com/o4zimIh.png) ## Interaction models - Modeling user interaction is important as it helps to identify user requirements - Modeling **system-to-system interaction** highlights the **communication problems** that may arise. - Modeling component interaction helps us understand if a proposed system structure is likely to deliver the **required system performance** and **dependability**. - ==Use case diagrams== and ==sequence diagrams== may be used for interaction modeling. ### Use case modeling - Each use case represents a discrete(有別的) task that involves external interaction with a system. - **Actors** in a use case may be **people** or **other systems** - Represented diagrammatically to provide an overview of the use case and in a more detailed textual form. #### Ex: Transfer-data use case ![](https://i.imgur.com/6uIrV5Z.png) #### Ex: Tabular description of the ‘Transfer data’ use-case ![](https://i.imgur.com/FWlwLah.png) #### Ex: Use cases in the Mentcare system involving the role ‘Medical Receptionist’ ![](https://i.imgur.com/4lBdgoc.png) ### Sequence diagrams - Used to model the interactions between the actors and the objects within a system. - Shows the sequence of interactions that take place during a particular use case or use case instance. #### Ex: Sequence diagram for View patient information ![](https://i.imgur.com/i5N7bAU.png) #### Ex: Sequence diagram for Transfer Data ![](https://i.imgur.com/4X0CHeG.png) ## Structural models - Structural models of **software display** the organization of a system in terms of the components that make up that system and their relationships. - Structural models may be static models, which show the structure of the system design, or dynamic models, which show the organization of the system when it is executing. - You create structural models of a system when you are discussing and designing the **system architecture**. ### Class diagrams - Class diagrams are used when developing an **objectoriented system model** to show the **classes** in a system and the associations between these classes. - An object class can be thought of as a **general definition** of one kind of system object. - An association is a **link** between classes that indicates that there is some **relationship** between these classes. #### Ex: UML classes and association ![](https://i.imgur.com/R7DmESC.png) #### Ex: Classes and associations in the Mentcare system ![](https://i.imgur.com/Z8P5H5z.png) #### Ex: The Consultation class ![](https://i.imgur.com/xapIrwp.png) ## Generalization - Rather than learn the detailed characteristics of every entity that we experience, we place these entities in more general classes (animals, cars, houses, etc.) and learn the characteristics of these classes. - In modeling systems, it is often useful to examine the classes in a system to see if there is scope for generalization. If changes are proposed, then you do not have to look at all classes in the system to see if they are affected by the change. - In object-oriented languages, such as Java, generalization is implemented using the **class inheritance mechanisms** built into the language. - In a generalization, the attributes and operations associated with higher-level classes are also associated with the lower-level classes. - The lower-level classes are subclasses inherit the attributes and operations from their superclasses. These lower-level classes then add more specific attributes and operations. #### Ex: A generalization hierarchy ![](https://i.imgur.com/Fdwcz9W.png) #### Ex: A generalization hierarchy with added detail ![](https://i.imgur.com/skWWwqO.png) ## Behavioral models - Behavioral models are models of the **dynamic behavior** of a system as it is **executing**. They show what happens or what is supposed to happen when a system responds to a stimulus from its environment. ### Data-driven modeling - Many business systems are **data-processing systems** that are primarily driven by data. They are **controlled** **by** the **data** input to the system, with relatively little external event processing. - Data-driven models show the sequence of actions involved in processing input data and generating an associated output - They are particularly useful during the analysis of requirements as they can be used to show **end-to-end processing** in a system. #### Ex: An activity model of the insulin pump’s operation ![](https://i.imgur.com/aYEwbkL.png) #### Ex: Order processing ![](https://i.imgur.com/PVdLS52.png) ### Event-driven modeling - **Real-time systems** are often **event-driven**, with **minimal data processing**. For example, a landline phone switching system responds to events such as ‘receiver off hook’ by generating a dial tone. - Event-driven modeling shows how a system responds to external and internal events. - It is based on the assumption that a system has a **finite number of states** and that **events** (stimuli) may cause a transition from one state to another. ### State machine models - These model the behavior of the system in response to external and internal events - They show the system’s responses to stimuli so are often used for modeling real-time systems - State machine models show system states as nodes and events as arcs between these nodes. When an event occurs, the system moves from one state to another. #### Ex: State diagram of a microwave oven ![](https://i.imgur.com/XgO97a8.png) #### Ex: Microwave oven operation ![](https://i.imgur.com/J8jfAAZ.png) ## Model-driven engineering - Model-driven engineering (MDE) is an approach to software development where models rather than programs are the principal outputs of the development process. - The programs that execute on a hardware/software platform are then generated automatically from the models. - Model-driven engineering is still at an early stage of development, and it is unclear whether or not it will have a significant effect on software engineering practice. ### Usage of model-driven engineering - Model-driven engineering is still at an **early stage of development**, and it is **unclear** whether or not it will have a **significant effect** on software engineering practice - Pros - Allows systems to be considered at higher levels of abstraction - Generating code automatically means that it is cheaper to adapt systems to new platforms. - Cons - Models for abstraction and **not necessarily right** for implementation. - Savings from generating code may be outweighed by the costs of developing translators for new platforms. ### Model-driven architecture - Model-driven architecture (MDA) was the precursor(前身) of more general model-driven engineering - MDA is a model-focused approach to software design and implementation that uses a subset of UML models to describe a system. - Models at different levels of abstraction are created. From a high-level, platform-independent model, it is possible, in principle, to generate a working program without manual intervention. ### Three type models of MDA method #### A computation-independent model (CIM) - These model the important domain abstractions used in a system. CIMs are sometimes called **domain models**. #### A platform-independent model (PIM) - These model the operation of the system **without reference** to its **implementation**. The PIM is usually **described using UML models** that show the static system structure and how it responds to external and internal events. #### Platform-specific models (PSM) - These are transformations of the platform-independent model with a separate PSM for each application platform. In principle, there may be **layers of PSM**, with each layer adding some **platform-specific detail**. ##### Ex: MDA transformations ![](https://i.imgur.com/IdODCe8.png) ##### Ex: Multiple platform-specific models ![](https://i.imgur.com/iEO5q1x.png)