1.25k likes | 1.3k Views
Explore modern Object-Oriented Analysis and Design (OOAD) with Unified Modeling Language (UML) and Rational Unified Process (RUP). Understand key principles, concepts, and methods for effective software architecture.
E N D
OO方法、RUP与UML建模 首席软件专家 张恂 博讯科技(上海)有限公司 浩方科技集团 2000.11
主要内容 一、OOAD与UML表示法 二、RUP建模过程与步骤 三、讨论
OO原则 • Abstraction(抽象) • Encapsulation(封装) • Modularity(模块化) • Hierarchy(分层)
OO三要素 • 封装 • 继承 • 多态
OO基本概念 • 对象 • 类 • 属性 • 操作(方法) • 接口(多态)* • 构件* • 关系 • 包 • 子系统*
接口与多态 • Polymorphism: The ability to hide many different implementations behind a single interface. • Interfaces formalize polymorphism, support “plug-and-play” architectures.
Component • A non-trivial, nearly independent, and replaceable part of a system that fulfills a clear function in the context of a well-defined architecture. • source code component, run time components, executable component
Subsystem • A combination of a package (can contain other model elements) and a class (has behavior) • Realizes one or more interfaces which define its behavior.
OOAD是主流技术 OOAD大部分情况下比结构化设计好: 结构化设计是过时的东西,它强调软件的结构按照功能来组织,一旦功能改变,软件的结构就会不稳定。 而OO设计把数据流和功能统一起来,IT行业绝大部分(70-80%)的软件设计(包括数据库设计)可以采用OO方法,目前国外流行的趋势也是这样,剩下的少部分有特定需求的可能还会用传统方法。 另外在电信界,用有限自动状态机的SDL方法仍占绝大数,但现在UML和SDL出现了融合的趋势。
Object Oriented Analysis • 用面向对象方法分析问题域,建立基于对象、消息的业务模型,形成对客观世界和业务本身的正确认识。 • 生成业务对象的动、静态模型和抽象类。
Object Oriented Design • 针对OOA给出的问题域模型,用面向对象方法设计出软件基础架构(概要设计)和完整的类结构(详细设计),以实现业务功能。 • 生成对象类的动、静态模型(解决域)。
Analysis Focus on understanding the problem Idealized design Behavior System Structure Functional requirements A small model Design Focus on understanding the solution Operations and Attributes Performance Close to real code Object lifecycles Non-functional requirements A large model Analysis vs. Design
“4+1”视图 • Use Case View (End-user: Functionality) • Logical View (Analysts/Designers: Structure) • Process View (System integrators: Performance, Scalability, Throughput) • Implementation View (Programmers:Software management) • Deployment View (System engineering: System Topology, Delivery, installation, communication)
Use Case Diagram Sequence Diagram Class Diagram Collaboration Digram State Diagram Activity Diagram Component Diagram Deployment Diagram UML图示
Actor - 用户 • “An Actor defines a coherent set of roles that users of use cases play when interacting with use cases. An actor has one role for each use case with which it communicates.” • 角色的集合,可以是人或外部系统。 • 定义了“系统边界”。
Use Case - 用例 • The specification of a sequence of actions, including variants, that a system (or other entity) can perform, interacting with actors of the system. • A use case is a coherent unit of functionality provided by a system, a subsystem, or a class as manifested by sequences of messages exchanged among the system and one or more outside interactors (called actors) together with actions performed by the system.
Business - System • 例子
Use Case依赖关系 • Association – The participation of an actor in a use case, i.e. instances of the actor and instances of the use case communicate with each other. This is the only relationship between actors and use cases. • Extend – An extend relationship from use case A to use case B indicates that an instance of use case B may be extended (subject to specific conditions specified in the extension) by the behavior specified by A. The behavior is inserted at the location defined by the extension point in B which is referenced by the extend relationship.
Use Case依赖关系 • Generalization – A generalization from use case A to use case B indicates that A is a specialization of B. • Include – An include relationship from use case A to use case B indicates that an instance of the use case A will also include the behavior as specified by B. The behavior is included at the location which defined in A.
Sequence Diagram A diagram that shows object interactions arranged in time sequence. In particular, it shows the objects participating in the interaction and the sequence of messages exchanged. Unlike a collaboration diagram, a sequence diagram includes time sequences but does not include object relationships. A sequence diagram can exist in a generic form (describes all possible scenarios) and in an instance form (describes one actual scenario). Sequence diagrams and collaboration diagrams express similar information, but show it in different ways.
Use Case描述 • 简述: This use case allows a Student to register for course offering in the current semester. The Student can also update or delete course selections if changes are made within the add/drop period at the beginning of the semester. The Course Catalog System provides a list of all the course offerings for the current semester.
事件流 Basic Flow: This use case start when a Student wishes to register for course offerings, or to change his/her existing course schedule. 1. The system requests that the Student specify the function he/she would like to perform (either Create a Schedule, Update a Schedule, or Delete a Schedule). 2. Once the Student provides the requested information, one of the subflows is executed. If the Registrar selected “Create a Schedule”, the Create a Schedule subflow is executed. (Update a Schedule, Delete a Schedule)
Create a Schedule 1. The system retrieves a list of available course offerings from the Course Catalog System and displays the list to the Student. 2. The Student selects 4 primary course offerings and 2 alternate course offerings from the list of available offerings. 3. Once the student has made his/her selections, the system creates a schedule for the Student containing the selected course offerings. 4. The Submit Schedule subflow is executed.
类的划分 • 边界类 • 控制类 • 实体类
理解Use Case和Actor 1)Use Case绝不是锦上添花的东西,一方面它可以促进与用户沟通,理解正确的需求,另一方面它可以划分系统与外部实体的界限,是系统设计的起点,而最终应该落实到类和实现代码上。 2)Use Case View与Logical View应该由明确的相关性。UML中从Use Case到类包的关联可以用依赖(或实现)关系描述。 3)Actor不是指人,而是指代表某一种特定功能的角色,因此同一个人可能对应很多个Actor。Actor是虚拟的概念,可以指外部系统和设备。 4)Use Case是对系统行为的动态描述,它是OO设计的起点,是类、对象、操作的来源,而通过逻辑视图的设计,可以获得软件的静态结构。
Class Diagram A diagram that shows a collection of declarative (static) model elements, such as classes, types, and their contents and relationships.
Export Control • Public The element is visible outside of the enclosing package and you can import it to other portions of your model. Operations are accessible to all clients. • Protected The element is accessible only to nested classes, friends, or to the class itself. • Private The element is accessible only to nested classes, friends, or to the class itself. • Implementation The element is visible only in the package in which it is defined. An operation is part of the implementation of the class.
类的并发性 • Sequential (default) - The semantics of the class are guaranteed only in the presence of a single thread of control. Only one thread of control can be executing in the method at any one time. • Guarded - The semantics of the class are guaranteed in the presence of multiple threads of control. A guarded class requires collaboration among client threads to achieve mutual exclusion. • Active - The class has its own thread of control. • Synchronous - The semantics of the class are guaranteed in the presence of multiple threads of control; mutual exclusion is supplied by the class.
参数化和实例化类 • Parameterized/Instantiated Class • C++ Template
关系 • Association • Aggregation • Composition • Dependency • Realization • Generalization (inheritance)
聚合关系 • Aggregation: A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts.
合成关系 • Composition: A form of aggregation with strong ownership and coincident liftimes. The parts cannot survive the whole/aggregate.
Association • 关联类
Multiplicity • 关系的多重性 • Exactly One: 1 • Zero or more: 0..n • One or more: 1..n • Zero or one: 0..1 • Specified range: 2..4 • Multiple, disjoint ranges: 2,4..6
Generalization • inheritance
Dependency • A dependency indicates a semantic relationship between two (or more) model elements. It relates the model elements themselves and does not require a set of instances for its meaning. It indicates a situation in which a change to the target element may require a change to the source element in the dependency.
依赖关系 • bind – Binding: A binding of template parameters to actual values to create a nonparameterized element. • trace – Trace: A historical connection between two elements that represent the same concept at different levels of meaning. • refine – Refinement: A historical or derivation connection between two elements with a mapping (not necessarily complete) between them.