UML 类图构造 [英] UML Class Diagram construction
问题描述
在使用以下信息绘制类图时遇到一些麻烦:
Having a bit of trouble coming with a class diagram using the following information:
- 一个人拥有零个或多个房屋.
- 抵押贷款有开始日期和结束日期.
- 抵押贷款有总额,包括每月还款额.
- 银行存储有关每个人的国民保险号和工资的信息,这些信息要求抵押房屋.
- 抵押属于一个人.
- 一所房子可以有零个或多个抵押贷款,但它只归一个人所有.
- 房屋具有价值,可作为相关联的银行担保抵押贷款.
- 一个人有零个或多个抵押贷款.
一个人可以申请抵押贷款来买房.
- A person owns zero or more houses.
- A mortgage has a start date and an end date.
- A mortgage has a total and consists of monthly payments.
- The bank stores information on the National Insurance Number and salary of each person, that request a mortage for a house.
- A mortgage belongs to one person.
- A house can have zero or more mortgages on it but it is owned by only one person.
- A house has a value and acts as a bank security for associated mortgages.
- A person has zero or more mortgages.
A person may apply for a mortgage to buy a house.
1 Owns * hasSecurity
Person ------------> House <--------------- Bank
-NINumber -address
-salary -value
|
| has
|
\/*
Mortgage
-startDate
-EndDate
-total
-monthlyPayments
有人能建议这是如何建模的.使用图表的示例将不胜感激.
Would someone be able to suggest how this is modeled. Examples using diagrams would be appreciated.
推荐答案
我认为您对所有这些信息感到困惑.
I think you are getting confused with all those information.
(1) 您可以从类图开始,确定哪些类交互,留下数量、属性和下一步的关系.
(1) You may start with class diagrams by identifying which classes interact, leaving quantities , properties, & relationships for the next steps.
像这样:
............................................
..+--------------+........+--------------+..
..| Person |........| Mortage |..
..+--------------+........+--------------+..
............................................
..+--------------+........+--------------+..
..| House |........| Bank |..
..+--------------+........+--------------+..
............................................
..+--------------+..........................
..| Payment |..........................
..+--------------+..........................
............................................
注意,这个不完整的图表还没有属性、关系、操作等.有一些点代表空白页.
Watch, that this incomplete diagram, doesn't have properties, relationships, operations, etc., yet. There are some dots that represent the blank page.
(2) 根据给定的信息,识别 &赋值,&每个实体或类的属性.
(2) From the given information, identify & assign values, & properties for each entity or class.
不要将表示内部值(Mortage.StartDate")的属性与表示与其他类或对象的关系的属性(房子可以有零个或多个抵押")混合在一起.
Do not mix those properties that represent an internal value ("Mortage.StartDate"), from properties that represent a relationship to other classes or objects ("A House can have Zero or More Mortages").
仅具有内部属性的类的示例可能是:
An example of a classs with only internal properties could be:
....................
..+--------------+..
..| Mortage |..
..+--------------+..
..| StartDate |..
..| EndDate |..
..| Total |..
..+--------------+..
....................
属性用一个项目符号列表表示,我们通常在每个属性前使用+",后面你会看到它可以改变:
Properties are represented by a list of bullets, we commonly use "+" before each property, later, you see it can be changed:
.......................
..+-----------------+..
..| Mortage |..
..+-----------------+..
..| [+] StartDate |..
..| [+] EndDate |..
..| [+] Total |..
..+-----------------+..
.......................
不要将项目上的+"与类角落上的+"混淆.
Do not confuse the "+" on the items, with the "+" on the corners of the classes.
有时,类可能会显示它的一些属性,或者根本不显示属性,即使有它.这可以用一个空白的部分框或一个带有 3 个点的框来表示:
Sometimes, classes may show some of its properties, or not properties at, all, even if the have it. This can be represented by a blank section box, or a box with 3 dots:
..................................................
..+-----------------+........+-----------------+..
..| Mortage |........| House |..
..+-----------------+........+-----------------+..
..| ... |........| |..
..+-----------------+........+-----------------+..
..................................................
具有代表其他对象或类的属性的类的示例,无论是链接、参考文献还是子部分:
An Example of a class with properties that represent other objects or classes, wheter links, or references, or subparts:
..................................................
..+-----------------+........+-----------------+..
..| Mortage |....+---+ House |..
..+-----------------+....|...+-----------------+..
..| [+] Owner +----+...| ... |..
..+-----------------+........+-----------------+..
..................................................
并且,表示具有这两种属性的类或对象,最好在不同的部分.
And, represent a class or object with both kind of properties, preferably in a different section.
....................................................
..+-----------------+........+-----------------+....
..| Mortage |........| Person |....
..+-----------------+........+-----------------+....
..| [+] StartDate |........| [+] Salary |....
..| [+] EndDate |........| |....
..| [+] Total |........| |....
..+-----------------+........+-----------------+....
..| [+] Owner +----+...| [+] Houses |....
..+-----------------+....|...+--------+--------+....
.........................|............|.............
.........................|............|.............
.........................|............|.............
.........................|...+--------+--------+....
.........................|...| House |....
.........................|...+-----------------+....
.........................|...| |....
.........................+---+ ... |....
.............................| |....
.............................+-----------------+....
.............................| [+] Owner |....
.............................| [+] Mortages |....
.............................+-----------------+....
....................................................
请注意,还有几种类型的关系,用箭头、三角形、菱形表示,让我们暂时跳过这一点,只使用一条线,表示 2 个类之间存在某种关系".
Note, also that there are several types of relationships, represented with arrows, triangles, diamonds, lets skip this for a moment, and use just a line, that represents that "there some kind of relationship" between 2 classes.
(3) 有一次,你已经确定了基本属性之间的区别表示关系的属性,您可以描述图表中的所有关系.
(3) Once, you have identify the difference between basic properties & properties that represent relationships, you may describe all relationships in your diagram.
............................................
..+--------------+........+--------------+..
..| Payment |........| Person |..
..+--------------+........+--------------+..
..| [+] Mortage |........| [+] Houses |..
..| |........| |..
..| |........| |..
..+------+-------+........+-------+------+..
.........|........................|.........
.........|........................|.........
.........|........................|.........
..+------+-------+........+-------+------+..
..| Mortage |........| House |..
..+--------------+........+--------------+..
..| [+] Owner |........| [+] Owner |..
..| [+] House +--------+ |..
..| |........| |..
..+-------+------+........+--------------+..
..........|.................................
..........|.................................
..........|.................................
..+-------+------+..........................
..| Bank |..........................
..+--------------+..........................
..| [+] Debtors |..........................
..+--------------+..........................
............................................
注意有一些关系,是间接的,比如一个人按月还款给抵押,但与人的还款关系不是直接显示的,而是通过抵押来显示的.
Note that there are some relationship, that are indirect, example, a monthly payment is performed to a mortage by a person, yet the payment relationship to the person, is not displayed directly, instead, its displayed thru the mortage.
(4) 在 UML 中,类之间有多种关系.一些关系,必须与对象创建有关.
(4) There are several kinds of relationships among classes, in UML. Some relationships, have to due with object creation.
(5) 也有独立于其他对象存在的对象,以及对象存在依赖于另一个对象的场景.而且,这构成了 2 种不同类型的对象.
(5) There also objects where exist independently of others, and, scenarios where an object existance depends on another object. And, that makes 2 different kind of objects.
例如,付款取决于抵押贷款的存在.无论是否有业主、业主银行或抵押贷款,房子都存在.无论是房屋抵押贷款还是债务人,银行都存在.
For example, Payments depends on the existance of a Mortage. A House exist wheter there is a Owner Person, or a Owner Bank, or It has Mortages. A Bank existe wheter there is a Mortage to a House, or a Debtor.
当一个对象或类依赖于另一个类时,它的关系称为组合",用一个实心菱形表示,在关系箭头的边缘,主类在那里.
When an object or class depends on another class, its relationship is called "Composition", and its represented by a filled diamond, at the edge of the relationship arrow, where the main class if.
....................
..+--------------+..
..| Payment |..
..+--------------+..
..| [+] Mortage |..
..| |..
..| |..
..+------+-------+..
.........|..........
.........|..........
.........|..........
.........^..........
........<*>.........
..+------v-------+..
..| Mortage |..
..+--------------+..
..| ... |..
..+--------------+..
....................
(6) 如果一个对象与另一个对象分开存在,但是存在某种关联,称为聚合",其表示类似,但是,带有未填充的空菱形,而不是.
(6) In cases, where an object exist separatelly from another object, but, there is some kind of association, Its called an "Aggregation", and its represented similar, but, with an non-filled empty diamond, instead.
....................
..+--------------+..
..| Person |..
..+--------------+..
..| [+] Houses |..
..+------^-------+..
........< >.........
.........v..........
.........|..........
.........|..........
.........|..........
..+------+-------+..
..| House |..
..+--------------+..
..| ... |..
..+--------------+..
....................
(7) 在关系中,应用了数量.多"的概念,通常用星号*"显示.
(7) In relationships, quantities are applied. The "many" concept, is usually displayed with an asterisk "*".
这个图表,带有数量可能是这样的:
This diagram, with quantites may be like:
............................................
..+--------------+........+--------------+..
..| Payment |........| Person |..
..+--------------+........+--------------+..
..| [+] MonthNo |........| |..
..+--------------+........| |..
..| [+] Mortage |........| [+] Houses |..
..| |........| |..
..+------+-------+........+-------^------+..
.........|..12...................< >.1......
.........|........................v.........
.........|........................|.........
.........^ .......................|.........
........< >.1.....................|..*......
..+------v-------+........+-------+------+..
..| Mortage |........| House |..
..+--------------+........+--------------+..
..| [+] Ammount |........| [+] Address |..
..+--------------+........+--------------+..
..| [+] Owner |.*...1.^| [+] Owner |..
..| [+] House +------< > |..
..| |.......v| |..
..+-------+------+........+--------------+..
..........|..*..............................
..........|.................................
..........|.................................
..........^.................................
.........< >.1..............................
..+-------v------+..........................
..| Bank |..........................
..+--------------+..........................
..| [+] Debtors |..........................
..| [+] Mortages |..........................
..+--------------+..........................
............................................
(8) 还有其他适用于 Class & 的概念.对象图,如继承关系.或者,添加其他类,例如请求"类.让我们暂时跳过它.
(8) There are other concepts that apply to Class & Object Diagrams, like Inheritance Relationships. Or, add other classes, such a "Request" class. Lets skip it for now.
一个可能的最终类图可能是:
A possible final class diagram could be:
...............................................
..+----------------+........+---------------+..
..| Payment |........| Person |..
..+----------------+........+---------------+..
..| [+] MonthNo |........| [+] FirstName |..
..| [+] Ammount |........| [+] LastName |..
..+----------------+........| [+] NINNo |..
..| [+] Mortage |........| [+] Salary |..
..| |........+---------------+..
..| |........| [+] Houses |..
..| |........| |..
..+-------+--------+........+-------^-------+..
..........|..12....................< >.1.......
..........|.........................v..........
..........|.........................|..........
..........^ ........................|..........
.........< >.1......................|..*.......
..+-------v--------+........+-------+-------+..
..| Mortage |........| House |..
..+----------------+........+---------------+..
..| [+] StartDate |........| [+] Address |..
..| [+] FinishDate |........| [+] Value |..
..| [+] Total |........| |..
..+----------------+........+---------------+..
..| [+] Owner |.*...1.^| [+] Owner |..
..| [+] House +------< > |..
..+-------+--------+.......v+---------------+..
..........|..*................................
..........|...................................
..........|...................................
..........^...................................
.........< >.1................................
..+-------v------+............................
..| Bank |............................
..+--------------+............................
..| [+] Name |............................
..+--------------+............................
..| [+] Debtors |............................
..| [+] Mortages |............................
..+--------------+............................
..............................................
干杯.
[别忘了为小猫打开金枪鱼罐头]
[Don't forget to open a tuna can for the kitty]
这篇关于UML 类图构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!