CPT203 W6
This’s the note of System Modeling
.
- Context models
- Interaction models
- Structural models
- Behavioral models
- Model-driven engineering
这周各种东西要记的也太多了吧。。。
Lecture
Basic Terms
Software Process
- Requirements Engineering 需求工程
- System Modelling 系统建模
- System Architecture 系统架构
- System Design 系统设计
为什么modeling很重要?
建模通过将复杂系统抽象为适当的细节级别来简化复杂系统
垃圾的software development失败大多可以归结于:
- Poorly understood requirements 知之甚少的需求
- Problems often discovered late in the development 问题往往在开发的后期发现
- Complexity lead to performance issues 复杂性会导致性能问题
System modeling
- System modeling is the process of developing abstract models of a system, with each model presenting a different view or perspective of that system. 系统建模是开发系统抽象模型的过程,每个模型呈现系统的不同视图或透视图。
- System modeling has now come to mean representing a system using some kind of graphical notation, which is now almost always based on notations in the Unified Modeling Language (UML). 系统建模现在已经意味着使用某种图形符号来表示系统,现在几乎总是基于统一建模语言(UML)中的符号。
- System modelling 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. They help clarify what the existing system does and can be used as a basis for discussing its strengths and weaknesses. These then lead to requirements for the new system. 在需求工程中使用现有系统的模型。它们有助于澄清现有系统的功能,并可作为讨论其优缺点的基础。这就导致了对新系统的需求。
- Models of the new system are used during requirements engineering to help explain the proposed requirements to other system stakeholders. Engineers use these models to discuss design proposals and to document the system for implementation. 在需求工程期间使用新系统的模型,以帮助向其他系统涉众解释建议的需求。工程师使用这些模型来讨论设计建议,并记录系统的实施。
- In a model-driven engineering process, it is possible to generate a complete or partial system implementation from the system model. 在模型驱动的工程过程中,可以从系统模型生成完整或部分的系统实现。
System perspective 系统的视角
- 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. 行为视角,你可以建模系统的动态行为以及它如何响应事件。
UML diagram types
- Activity diagrams, which show the activities involved in a process or in data processing.
- Use case diagrams, which show the interactions between a system and its environment.
- Sequence diagrams, which show interactions between actors and the system and between system components.
- Class diagrams, which show the object classes in the system and the associations between these classes.
- State machine diagrams, which show how the system reacts to internal and external events.
PS: 在用例图中,我们总是会选择的最简单的事件进行记录(as simply as possible)。而且在用例图中,事件并不是以flow的形式存在的(或是说存在flow的内容都被use case省略到一个事件里的?)。但是在activity diagram中,事件就是会有flow的形式存在。
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. 模型必须正确和完整。
PS: 这里需要注意,模型的正确与否和是否完整并没有一个固定的要求,不同的情况对模型的要求是不一样的。有的时候不完整或者不正确的模型就可以开始讨论了,有时候需要完全正确和完整。
The context of the MHC-PMS
Context models
- Context models simply show the other systems in the environment, not how the system being developed is used in that environment. 上下文模型只是显示环境中的其他系统,而不是正在开发的系统如何在该环境中使用。
- Used along with other models, such as business process models. 与其他模型一起使用,如业务流程模型。
- UML activity diagrams may be used to define business process models. UML活动图可以用来定义业务流程模型。
Process model of involuntary detention
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 diagram
- Use cases are developed originally to support requirements elicitation and now incorporated into the UML. 用例最初是为了支持需求引出而开发的,现在被合并到UML中。
- 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 diagramatically to provide an overview of the use case and in a more detailed textual form. 以图表形式表示,以更详细的文本形式提供用例的概述。
Transfer-data use case
A use case in the MHC-PMS
“传输数据”用例的表格式描述 Tabular description of the ‘Transfer data’ use-case
Use cases in the MHC-PMS involving the role ‘Medical Receptionist’
Sequence diagrams
- Sequence diagrams are part of the UML and are used to model the interactions between the actors and the objects within a system. 序列图是UML的一部分,用于对系统中参与者和对象之间的交互进行建模。
- A sequence diagram shows the sequence of interactions that take place during a particular use case or use case instance. 序列图显示了在特定用例或用例实例中发生的交互序列。
- The objects and actors involved are listed along the top of the diagram, with a dotted line drawn vertically from these. 所涉及的对象和参与者在图表的顶部列出,并在垂直方向上画一条虚线。
- Interactions between objects are indicated by annotated arrows. 对象之间的交互通过标注的箭头表示。
Sequence diagram for View patient information
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 object- oriented 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. 关联是类之间的链接,表明这些类之间存在某种关系。
- When you are developing models during the early stages of the software engineering process, objects represent something in the real world, such as a patient, a prescription, doctor, etc. 当你在软件工程过程的早期阶段开发模型时,对象代表了现实世界中的某些东西,如病人、处方、医生等。
这就是类图的作用,具体细节自行查询并学习(课件上有一些介绍),在大二的CPT105中学过如何绘制Java的UML类图。
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. 行为模型是系统在执行过程中动态行为的模型。它们显示了当系统对环境的刺激作出反应时发生了什么或应该发生什么。
- You can think of these stimuli as being of two types: 这些刺激分为两种
- Data Some data arrives that has to be processed by the system. 一些到达的数据必须被系统处理。
- Events Some event happens that triggers system processing. Events may have associated data, although this is not always the case. 事件触发系统处理的事件。事件可能有相关的数据,尽管情况并非总是如此。
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. 它们在需求分析期间特别有用,因为它们可以用来显示系统中的端到端处理。
- Activity diagram and sequence diagram are used in data-driven modeling. 数据驱动建模使用活动图和序列图。
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 diagram 状态机图
- These model the behaviour of the system in response to external and internal events. 这些模型模拟系统在响应外部和内部事件时的行为。
- They show the system’s responses to stimuli so are often used for modelling 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. 状态机模型将系统状态显示为节点,事件显示为节点之间的弧线。当事件发生时,系统从一种状态转移到另一种状态。
- Statecharts are an integral part of the UML and are used to represent state machine models. 状态图是UML不可分割的一部分,用于表示状态机模型。
然后需要有说明状态的表格
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. 模型驱动工程(MDE)是一种软件开发方法,在这种方法中,模型而不是程序是开发过程的主要输出。
- The programs that execute on a hardware/software platform are then generated automatically from the models. 在硬件/软件平台上执行的程序会从模型中自动生成。
- Proponents of MDE argue that this raises the level of abstraction in software engineering so that engineers no longer have to be concerned with programming language details or the specifics of execution platforms. MDE的支持者认为这提高了软件工程的抽象层次,这样工程师就不必再关注编程语言的细节或者执行平台的细节。
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. 为新平台开发翻译程序的成本可能超过了生成代码所节省的成本。
Types of model
- A computation independent model (CIM) 一个独立计算的模型
- These model the important domain abstractions used in a system. CIMs are sometimes called domain models. 这些模型为系统中使用的重要领域抽象建模。cim有时被称为域模型。
- 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. 这些模型模拟系统的运行,而不参考系统的实现。通常使用UML模型来描述PIM, UML模型显示静态系统结构以及它如何响应外部和内部事件。
- 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. 这些是平台独立模型的转换,每个应用平台都有一个独立的PSM。原则上,可以有多个PSM层,每一层都添加一些特定于平台的细节。
Agile methods and MDA
- The developers of MDA claim that it is intended to support an iterative approach to development and so can be used within agile methods. MDA的开发人员声称,MDA旨在支持迭代开发方法,因此可以在敏捷方法中使用。
- The notion of extensive up-front modeling contradicts the fundamental ideas in the agile manifesto and I suspect that few agile developers feel comfortable with model- driven engineering. 广泛的预先建模的概念与敏捷宣言中的基本思想相矛盾,我怀疑很少有敏捷开发人员能够适应模型驱动的工程。
- If transformations can be completely automated and a complete program generated from a PIM, then, in principle, MDA could be used in an agile development process as no separate coding would be required. 如果转换可以完全自动化,并且可以从PIM生成一个完整的程序,那么原则上,MDA可以在敏捷开发过程中使用,因为不需要单独的编码。
Executable UML
- The fundamental notion behind model-driven engineering is that completetly automated transformation of models to code should be possible. 模型驱动工程背后的基本概念是,完全自动化的模型到代码的转换应该是可能的。
- This is possible using a subset of UML2, called Executable UML or xUML. 使用UML2的子集,称为可执行UML或xUML,这是可能的。
Features of executable UML
- To create an executable subset of UML, the number of model types has therefore been dramatically reduced to these 3 key types: 为了创建一个UML的可执行子集,模型类型的数量已经戏剧性地减少到以下3种关键类型
- Domain models that identify the principal concerns in a system. They are defined using UML class diagrams and include objects, attributes and associations. 识别系统中主要关注点的领域模型。它们是使用UML类图定义的,包括对象、属性和关联。
- Class models in which classes are defined, along with their attributes and operations. 定义类及其属性和操作的类模型。
- State models in which a state diagram is associated with each class and is used to describe the life cycle of the class. 状态模型,其中状态图与每个类相关联,用于描述类的生命周期。
- The dynamic behavior of the system may be specified declaratively using the object constraint language (OCL), or may be expressed using UML’s action language. 系统的动态行为可以使用对象约束语言(OCL)声明地指定,也可以使用UML的动作语言表达。
Key points
- A model is an abstract view of a system that ignores system details. Complementary system models can be developed to show the system’s context, interactions, structure and behavior. 模型是忽略系统细节的系统抽象视图。可以开发互补系统模型来显示系统的上下文、交互、结构和行为。
- Context models show how a system that is being modeled is positioned in an environment with other systems and processes. 上下文模型显示了一个被建模的系统如何与其他系统和流程一起定位在环境中。
- Use case diagrams and sequence diagrams are used to describe the interactions between users and systems in the system being designed. Use cases describe interactions between a system and external actors; sequence diagrams add more information to these by showing interactions between system objects. 用例图和序列图用于描述被设计的系统中用户和系统之间的交互。用例描述系统和外部参与者之间的交互;序列图通过显示系统对象之间的交互,为它们添加了更多的信息。
- Structural models show the organization and architecture of a system. Class diagrams are used to define the static structure of classes in a system and their associations. 结构模型显示系统的组织和架构。类图用于定义系统中类的静态结构及其关联。
- Behavioral models are used to describe the dynamic behavior of an executing system. This behavior can be modeled from the perspective of the data processed by the system, or by the events that stimulate responses from a system. 行为模型用于描述执行系统的动态行为。可以从系统处理的数据的角度,或者从刺激系统响应的事件的角度,对这种行为进行建模。
- Activity diagrams may be used to model the processing of data, where each activity represents one process step. 活动图可以用来建模数据的处理,其中每个活动代表一个过程步骤。
- State diagrams are used to model a system’s behavior in response to internal or external events. 状态图用于对系统响应内部或外部事件的行为进行建模。
- Model-driven engineering is an approach to software development in which a system is represented as a set of models that can be automatically transformed to executable code. 模型驱动工程是一种软件开发方法,在这种方法中,系统被表示为一组可以自动转换为可执行代码的模型。
References
- XJTLU slides CPT203 Week6
期中加油