软件技术
软件技术
编译环境设置
下载Maven
到这个链接 里下载maven的包
然后解压到某个目录下,
配置环境变量
把maven目录下的bin目录添加到path里面
然后可以用 mvn -v 检查配置情况
Lecture 2
Software lifecycle
分析问题
要从问题中提取功能,然后记录在backlog上:
比如说:
Bumpers is a game where cars drive on a game board and can crash each other. In each collision, there is a winning car. The car that wins all collisions is the winner of the game. The player can start and stop the game. When the game is started, music is played. A car can be either fast or slow. There is one car controlled by the player. The player can steer the direction of the car with the mouse and change its speed. The game should be platform independent. It should visualize different parameters of the car, e.g. the speed, consumption and location of the car. When cars crash, there has to be a sound effect. The game should support different collisions. The determination of the collision winner should be changeable during gameplay.
所以我们可以依次列出一个清单
- Cars drive on the game board
- Cars collide with each other and each collision has a winning car
- The winner of the game is the car that wins all the collisions
- The player starts and stops the game
- Music plays when the game begins and stops to play when the game ends
- The game supports different car types
- The player steers the car with the mouse
- The player can change their car’s speed
- The game should be compatible with multiple platforms
- The speed, consumption, and location of the player’s car is visualized in an instrument panel
- Collisions follow the “right before left” rule, and thus right-most cars win the collisions
- A crash sound and/or animation plays when two cars collide
- The game supports different collisions, the determination of the winner is changeable during game play.
UML 图
Scenario格式
Use Case Diagram
他是可以从用户的角度展示一个系统功能的图,比如
Actor 是使用这个系统的人
- 用户
- 外部系统
- 物理环境(天气)
Association
«includes»
重复使用一个功能
«extends»
不是总是发生的情况
比如:
Collect money可能会被其他东西使用。Out of order是一个例外情况,不是总是发生
Bumper的Use Case 图
(1)Cars drive on the game board
(4)The player starts and stops the game
- Music plays when the game begins and stops to play when the game ends
Class Diagram
比如说这样一个描述类的图,有方法,属性还有关系
类的属性
- 类名斜线,表示是个abstract类
- Attribute 中
- - 表示private
- + 表示public
- ~ 表示在包中可见(不加修饰符)
Association
Inheritance: 继承 Realization: 接口实现 Dependency: 依赖 Aggregation 拥有关系 Compositon 构成关系
- Compositon 和Aggregation类似,但是类不能独立存在,必须依附于其中一个类
Dependency 中,一个类中的方法会用到另一个类,比如
Cardinality
这个是在关系上的数字。比如1个或者多个拥有关系
为了画出这样一个图首先我们要找出主要的对象
Abbot’s Technique
我们可以找出关键词汇,来帮我们建图
Bumper的类图
我们提取出其中的关键文字:
Analysis, design, implementation and delivery of Bumpers
Lecture 3 需求分析
需求的种类
Functionality requirements
actors,
Nonfunctional requirements
- Quality requirements:
- Usability
- Realiability
- Performance
- Supportability
- Quality requirements:
Functionality
它指的是系统与外部的交互
- Relationship of outputs to inputs
- Response to abnormal situations
- Exact sequence of operations
- Validity checks on the inputs
它需要写出一个动作的形式,比如
- Withdraw money
- Deposit mony
- Transfer money
- Loas cash card
Leture 4 系统设计 I
系统设计的8大问题
设计目标 Design goals
子系统分解 Subsystem decomposition
并发 Concurrency
硬件软件映射 Hardware/software mapping
管理现有数据 Persistent data management
全局资源处理 Global resource handling
软件控制 Software control
边界条件 Bondary conditions
它和需求分析的关系
设计目标 Design Goal
任何一个Nonfunctional requirment是一个设计目标。
取舍 trade-offs
设计目标经常会互相冲突
Functionality vs. usability
有100个功能的系统未必好用
Cost vs. robustness
低造价的系统往往不会检查错误
Efficiency vs. portability
Rapid development vs. functionality
Cost vs. reusability
Backward compatibility vs. readability
使得系统兼容会是代码可读性下降
子系统分解
子系统:类,关系,事件的集合
服务:子系统提供的外部可见的操作
子系统的内聚与耦合 Coupling and cohesion of subsystems
目标是在容许变换下减少系统复杂性
内聚Cohesion:在一个系统间类之间的依赖
耦合Coupling: 子系统间的依赖
系统分化模块要做到高内聚、低耦合。
实现高内聚
交互都是这个系统间的,不跨越系统
- 操作都是在相同的属性上
- 操作实现了相同的功能或服务
实现低耦合
调用一个类不需要知道这个类内部的东西
- 小的接口
- 信息隐藏
- 无全局数据
- 交互都是在子系统内部
架构风格
它是子系统分解的模式
UML 组件图 component diagram
它可以用组件和依赖关系的形式给出最高层次的系统设计的模型
- 提供的接口和使用某个接口
- 依赖 dependency
- 端口 port
Lecture 5 系统设计II
架构风格
MVC 架构风格
它可以用于解决高耦合(high coupling)的系统问题。
- Model: 处理和存储应用的主要数据 (entity objects)
- View: 把信息展示给用户 (boundary objects)
- Controller: 与用户交互且更新model
View和Controller共同构成用户接口
Repository架构风格
几个独立的程序在一起工作并且组成一个repository. 子系统只从repository里访问/修改数据
比如编译器的架构
用图像表示架构风格
- 组件Component 代表subsystem
- 连接 Connectors 代表 communication
层次架构 Layered architectural style
客户端服务架构 Client server architectural style
并发
它被用来解决非功能性需求中的:性能,响应时间,延时,可用性。
使用多线程的时候要注意同步
硬件软件映射
怎样把类模型映射到硬件/软件上。如何实现子系统
- Control objects -> processor
- Entity objects -> memory
- Boundary objects -> input/output device
部署图 deployment diagram
稳固的数据管理
- File system
- Database system
全局资源处理
在多用户系统中,不同用户对资源的权限不同。
我们可以使用 access matrix来做
软件控制
我们可以选择中心化的和去中心化的软件控制. 在communication diagram中,我们可以看到软件的中心化程序
- Fork diagram
- Stair diagram
边界条件
- 初始化 Initialization: 从开始到准备状态
- 停止 Termination: 清理资源
- 错误 Failure: 错误,bugs
我们可以用 use case 来建模
- Actor: often the system administrator
- Interesting use cases:
- Start up of a subsystem
- Start up of the full system
- Termination of a subsystem
- Error in a subsystem or component, failure of a subsystem or component
Object Design
代码重用的类型
黑盒重用 (aggregation and composition)
白盒重用 (inheritance)
设计模式
Bridge
Composite
Proxy
Adapter
Facade
Testing
Unit testing
Integration testing
Test all interfaces between subsystems and the interaction of subsystems
Stub
用来替代某个被调用的组件
Driver
用来调用其他组件
Bottm up
Top down
System testing
Dynamic analysis
Model based testing
Object oriented testing
Correct
- In object oriented testing, the test model can contain dummy
objects.
- SUT means system under test
- In object oriented testing doubles replace the SUT's collaborators during testing
- Typically, a factory or the test case initailizes mock objects. Mock objects are not part of the system model! There must not be a dependency from the system model to mock objects.
- In integration testing,
- bottom up integration testing is useful for testing real time systems. Because we have heavily rely on performance in real time systems. Bottom up integration testing makes sure to test the underlying funcitonality first. No doubles are needed to verify the expected behaviour.
- top down integration testing can result in a lot of doubles if the lowest level of the system contains many methods. No drivers are needed.
- vertical integration testing allows to always have an executable version of the system. We can test how the layers work togethor for specific functionality and have a working the system.
- They only cover one layer in the beginning. only at the end they cover all layers.(not always cover all layers).
- Unit Test
- Unit tests can be executed with JUnit
- Unit tests are typically used in development environments
- Unit tests can test whether a method's observed output is the same as the expected output
- An assertion verifies that a condition is met when the code is executed
Wrong
Lecture 11
Git
Correct
- Git
- To promote local changes, a developer needs to
add
,commit
andpush
. - Pull is a compound command to fetch and merge changes from the remote into the local repository
- Push will upload the commits from the local repository to the remote
- Merge conflicts should be resolved in the local repository
- To fetch changes from the remote repository, you need to be connected to the remote repository(online)
- The repository can be restored from a programmer's computer if the server crashes
- Distributed version control systems have a higher learning curve because their users need to understand multiple commands and actions,which is a disadvantage.
- Branches are lightweight
- Programmers could exchange commits directly without the need to store the version on the remote repository
- A change policy can, e.g., guarantee that each promotion conforms(遵从) to commonly accepted criteria(标准)
- In certain cases, a change request from the customer can also be rejected
- To promote local changes, a developer needs to
- Software Quality
- Different people have a different understanding of software quality
- Quality aspects can change over time
- Quality is difficult to measure
- Quality can be very subjective
- Advantages of code reviews
- There are more developers who understand the code
- Developers communicate more with each other
- Disadvantages of code reviews
- Reviewing code cost times. Code reviews slow down the initial development
- Static code analysis can find certain issues,but there are many issue types that can be found with a manual code review(not automated)
- activitys in Quality management
- Quality assurance
- Quality control
- prevent code duplication
- Refactoring
- Delegation
- Inheritance
- Scrum
- in scrum changes can occur all the time and can be integrated into the Product Backlog, as Scrum relies on an empirical process model.
- The Scrum Master is not a traditional project leader. The developers have much more control.
- Scrum Master should make sure that the team follows the Scrum process
- Trying out the software and providing feedback are responsibilities of the Product Owner. However, the product owner is not necessarily also an end user of the software.
- The Waterfall Model relies on a defined process model and therefore does not take changes into account.
Wrong
- Merge conflicts are resolved on the remote repository.
pull
is a compound command, composed offetch
andclone
.- Fetching changes can be done offline.
- Code reviews can be completely automated
Software Architecture
Correct
- Process Control
- A software architecture is an instance of an architectural style. The architecture style then serves as a pattern for a subsystem decomposition
- As empirical processes see changes as opportunities, they deal better with them then defined processes, which see them as errors.
Wrong
Process Control
Correct
Wrong
项目: Space Invader
Problem Statement
They have a high fun factor, no learning curve and short startup times.
As the duration of these games is short
TUM wants to have a simple and easy single player game
offer it for students to play during boring lectures
The data about when and how successfully the game is played shall be used to assess the quality of TUM’s educational program.The game shall be derived from the classic game Space Invaders
adjust the gameplay or the graphics for the purpose of being played during lectures.
The game should collect data about when the game is being played and how well the player is doing
it is possible to derive some assertions about how captivating the lecture was, that the player was supposed to pay attention to.
需求分析
Functional Requirements
Show scores (Evaluate how success the game is played)
Get Time data
Get Lecture Information
derive some assertions about how captivating the lecture was
start game
adjust pictures
Space Invader
move the spacecraft
shoot bullet
evaluate collision
Nonfunctional Requirements
- Usability:
- The player need at most 3 clicks to start a game.
- The player need at most 3 buttons to control the spacecraft
- Performace: The startup should finish in 1 second.
FR1: Show scores (Evaluate how success the game is played) FR2: Get Time data FR3: Get Lecture Information FR4: derive some assertions about how captivating the lecture was FR5: start game FR6: shoot bullet
NFR1 [Usability]: The player need at most 3 clicks to start a game. NFR2 [Usability]: The player need at most 3 buttons to control the spacecraft NFR3 [Performace]: The startup should finish in 1 second.
JavaFX
创建项目
https://openjfx.io/openjfx-docs/#maven
项目结构
1 | package de.tum.in.ase.eist.tumspaceinvaders; |
这两个文件的包目录是一样的
javaFX里面的控件是树状排列的
stage -> scene -> rootBorderPane
|
-> label
控件
Label
1 | BorderPane rootBorderPane = new BorderPane(); |
Button
1 | Button btn = new Button("Click Me"); |
事件处理器
内部类写法
1 | private class MyEventHandler implements EventHandler<ActionEvent> { |
匿名类写法:
1 | btn.setOnAction(new EventHandler<ActionEvent>() { |
lambda表达式写法
1 | btn.setOnAction(e -> System.out.println("hello")); |
Image
1 | Image image = new Image(new File("resources/bgimg1.jpg").toURI().toString()); |
添加其他窗口
可以用 SceneBuilder 来可视化定制界面: https://gluonhq.com/products/scene-builder/
打开就可以用图形界面来编辑窗口。
编辑完成了之后,可以得到一个 .fxml
文件,
1 |
|
首先我们要绑定对应的类:也就是设置 fx:controller
属性为对应的类, 我这里是
de.tum.in.ase.eist.view.ShopUI
.
然后再 ShopUI
类里,可以用Show Sample Controller
Skeleton来生成对应的代码
再copy到ShopUI
类里面
并且在module.info
里面要写
exports [package] to javafx.xml
其中 [package]
是ShopUI
所在的包. 然后并且还要写一行
opens ...
1 | module de.tum.in.ase.eist.tumspaceinvaders { |
然后可以从代码中导入预设
1 | private void openShop() { |
添加Junit测试
在pom.xml
中添加下面的依赖
1 | <dependency> |
然后创建test文件夹
一般就可以出现junit的依赖了,如果没有的话检查一下
.classpath
文件, 可以手动添加这个
1 | <classpathentry kind="src" output="target/test-classes" path="src/test/java"> |
pom.xml配置文件
打包项目
打包的时候,主程序不要extend Application
不然会出现找不到Javafx 的错误。 可以改成下面的方式:
1 | public class TumSpaceInvaders { |
添加plugin
在pom.xml
的build
中加入下面的插件,记得修改mainClass
等参数.
1 | <plugin> |
执行命令
在终端执行这个命令来打包
1 | mvn clean compile assembly:single |
或者在eclipse中选择 Run As
->
Maven build ...
然后再goal
中输入
clean compile assembly:single
执行完成后,会出现一个jar
文件,
可以这样来执行jar程序.
1 | java -jar xxx.jar |