UML: Class diagrams
Sunday, December 16, 2007 3:05:07 AM
Một sơ đồ Lớp(Class diagram) mang tới một cái nhìn tổng quan về một hệ thống bằng cách biểu diễn các lớp và những mối quan hệ giữa chúng trong hệ thống đó. Sơ đồ lớp được mô tả ở dạng tĩnh -- chúng hiển thị sự tương tác giữa các lớp trong hệ thống, nhưng không hiển thị sự việc xảy ra trong hệ thống khi chúng tương tác với nhau.
Sơ đồ lớp(Class diagram) bên dưới xây dựng mô hình một khách hàng đặt hàng từ một danh mục hàng bán lẻ(retail catalog). Lớp trung tâm là Order. Được liên kết với nó là Customer cho việc mua sắm và thanh toán. Một sự thanh toán thuộc một trong 3 loại: Tiền mặt, Thẻ tín dụng hay Sec. Đặt hàng có chứa OrderDetails, mỗi item trong Order liên kết tới một OrderDetails.

Ký hiệu lớp trong UML là một hình chữ nhật được chia thành 3 phần: class name, attributes, và operations. Tên của các lớp trừu tượng, như Payment, được in nghiêng. Những mối quan hệ giữa các lớp là những liên kết kết nối.
Các Lớp trong hệ thống có 3 kiểu quan hệ:
- Liên kết(association) -- a relationship between instances of the two classes. There is an association between two classes if an instance of one class must know about the other in order to perform its work. In a diagram, an association is a link connecting two classes.
- Tập hợp(aggregation) -- an association in which one class belongs to a collection. An aggregation has a diamond end pointing to the part containing the whole. In our diagram, Order has a collection of OrderDetails.
- Khái quát(generalization) -- an inheritance link indicating one class is a superclass of the other. A generalization has a triangle pointing to the superclass. Payment is a superclass of Cash, Check, and Credit.
An association has two ends. An end may have a role name to clarify the nature of the association. For example, an OrderDetail is a line item of each Order.
A navigability arrow on an association shows which direction the association can be traversed or queried. An OrderDetail can be queried about its Item, but not the other way around. The arrow also lets you know who "owns" the association's implementation; in this case, OrderDetail has an Item. Associations with no navigability arrows are bi-directional.
The multiplicity of an association end is the number of possible instances of the class associated with a single instance of the other end. Multiplicities are single numbers or ranges of numbers. In our example, there can be only one Customer for each Order, but a Customer can have any number of Orders.
This table gives the most common multiplicities.
Multiplicities Meaning
0..1 zero or one instance. The notation n . . m indicates n to m instances.
0..* or * no limit on the number of instances (including none).
1 exactly one instance
1..* at least one instance







Unregistered user # Saturday, August 15, 2009 2:49:49 PM
Unregistered user # Saturday, August 15, 2009 2:53:31 PM
Unregistered user # Friday, April 2, 2010 11:58:29 AM
Unregistered user # Monday, July 19, 2010 11:32:16 AM