UML class diagram

Source: Internet
Author: User
Tags modifiers

 

 

 

 

When drawing a class chart, clarifying the relationship between classes is the focus. Class relationships include generalization, implementation, dependency, and association ). The Association is divided into general association, aggregation, and composition ). The following describes the relationships with instances.

Basic Concepts

Class digraphs: class diagrams are the most common and important diagrams in object-oriented system modeling and are the basis for defining other diagrams. A class chart is a static model used to display the classes and interfaces in the system and their static structures and relationships.

Three basic components of a class chart: Class Name, attribute, and method.

Generalization: indicates the relationship between is-A, which is the most coupling relationship between objects. Subclass inherits all details of the parent class. Directly use the inheritance expression in the language. Use a solid line with a triangular arrow in the class diagram, and the arrow points from the subclass to the parent class.

Implementation: In the class diagram, it is the relationship between interfaces and implementations. There is nothing to talk about. In the class diagram, use a dotted line with a triangular arrow to indicate that the arrow points from the implementation class to the interface.

Dependency: the weakest association between objects. It is a temporary Association. Code generally refers to the call relationship between other objects established by local variables, function parameters, and return values. A class call is dependent on some methods in the class to fulfill some of the class's responsibilities. In the class chart, use a dotted line with an arrow to indicate that the arrow points from the class to the dependent class.

Association: A Reference relationship between objects, such as the relationship between the customer class and the order class. This relationship is usually expressed by class attributes. Association is divided into general association, aggregation Association, and combination Association. The last two types are analyzed later. In a class chart, use a solid line with an arrow to indicate that the arrow points from the class to the associated class. It can be unidirectional or bidirectional.

Aggregation: indicates the relationship between has-a, which is an unstable inclusion relationship. It is stronger than general association. It has a relationship between the whole and the local, and can exist separately without the whole. Such as the relationship between the company and its employees, the company includes employees, but if the company fails, employees can still change the company. In a class chart, a hollow diamond is used to indicate that the diamond points from the local to the whole.

Composition: indicates the contains-a relationship, which is a strong inclusive relationship. The composite class is responsible for the life cycle of the composite class. Is a stronger aggregation relationship. Some cannot be separated from the whole. For example, if the relationship between the company and the Department is absent, the Department cannot exist. The relationship between the problem and option in the questionnaire; the relationship between the order and the order option. In the class chart, the solid diamond is used to indicate that the diamond points from the local to the whole.

Multiplicity: usually used in association, aggregation, and combination. Indicates how many associated objects exist. It is represented by a number. Asterisk (number. For example, a cutover notification can be associated with 0 to N fault tickets.

Differences between aggregation and combination

These two are hard to understand. Let's focus on them. The difference between aggregation and combination is that the aggregation relationship is "has-a", and the combination relationship is "contains-a". The aggregation relationship indicates that the relationship between the whole and the part is relatively weak, the combination is relatively strong; the Objects representing some things in the aggregation relationship are irrelevant to the lifetime of the objects representing the aggregation things. Once an aggregation object is deleted, the Objects representing some things are not necessarily deleted. Once a composite object is deleted in the composite, the object representing some things is also deleted.

Instance analysis

Unicom customers respond to OSS. The system provides function modules such as fault tickets, Service Activation, resource verification, cutover, service re-protection, and network quality and performance. Now we will explain some of the requirements as an example.

You can refer to the class diagram for better understanding.

1. notifications include general notifications, cutover notifications, and reinsurance notifications. This is an inheritance relationship.

2. noticeservice and the implementation class noticeserviceimpl are implementation relationships.

3. noticeserviceimpl references notice through the Save parameter, which is a dependency. The basedao completion function is also called as a dependency.

4. cutover notification and fault ticket are generally associated by intermediate class (Notification circuit.

5. There is an aggregation relationship between the warranty notice and the pre-plan database. Because the pre-plan library can be input in advance, and there is no necessary link with the re-Warranty notification, it can exist independently. In the system, manually select from the list. Delete the re-Warranty notification without affecting the plan.

6. There is an aggregation relationship between cutover notification and request ticket. Similarly, a request ticket can exist independently of a cutover notification. That is to say, the cutover notification is deleted without affecting the ticket.

7. Notifications and replies are in a combination. Because the reply cannot exist independently of the notification. That is to say, to delete a notification, the corresponding reply to the notification should also be deleted in a cascade manner.

After the above analysis, I believe you have a good understanding of the relationship between classes. Do you have any other ideas or good opinions.

PS: Well, the above class diagram is drawn using enterprise definition 7.5. We recommend EA here, which is very good. It can replace Visio and Rose. Visio is not powerful enough, and Rose is too heavy. Only EA is suitable.

 

 

 

In UML modeling, it is essential to understand the elements that appear on a class diagram. Developers must understand how to convert elements on the class diagram to Java. Java is used as a representative to combine some online instances. Below are some basic collection and summary of the individual: basic element Symbol: 1. Class (classes) class contains three components. The first is the class name defined in Java. The second is attributes ). The third is the method provided by this class. You can append a visibility modifier before attributes and operations. The plus sign (+) indicates public visibility. Minus (-) indicates private visibility. # Indicates protected visibility. Omitting these modifiers indicates visibility at the package level. If an attribute or operation has an underscore, it indicates that it is static. In the operation, you can also list the parameters it accepts and the return type, as shown in:

2. package is a combination mechanism for common purposes. A package in UML corresponds directly to a package in Java. In Java, A package may contain other packages, classes, or both. During modeling, you usually have a logical package, which is mainly used to organize your model. You will also have a physical package, which is directly converted into a Java package in the system. The name of each package uniquely identifies the package.

3. An interface is a collection of operations that specify the services provided by a class. It directly corresponds to an interface type in Java. The interface can be expressed by the icon below (the circle symbol above, the interface name below the circle symbol, the line in the middle, and the method name below the line ), it can also be represented by a standard class appended with <interface>. Generally, you can know the relationship with other classes based on the interface in the class diagram.

Dependency: 1. A "use" Relationship Between dependencies indicates that the specification of an object may affect other instances dependent on it. More specifically, it can be converted to any type of reference to a class or object not in the instance scope. This includes a local variable that references an object obtained through method call (as shown in the following example ), or reference a static method of a class (there is no instance of that class at the same time ). You can also use "dependency" to indicate the relationship between packages. Because the package contains classes, you can express the relationship between packages and packages based on the relationships between classes in those packages.

2. a structured relationship between Association entities indicates that objects are connected to each other. The arrow is optional and is used to specify the navigation capability. Without arrows, it implies a two-way navigation capability. In Java, the Association is converted to an instance-scope variable, just like the code shown in the "Java" Area in Figure E. You can append other modifiers to an association. The multiplicity modifier implies the relationship between instances. In the Demo code, the employee can have 0 or more timecard objects. However, each timecard only belongs to a single employee.

3. Aggregation is a form of association, representing the overall/local relationship between two classes. Aggregation implies that the whole is at a level higher than the local level, while association implies that two classes are at the same level in concept. Aggregation is also converted to an instance scope variable in Java. The difference between Association and aggregation is purely conceptual and strictly reflected in semantics. Aggregation also implies that there is no loop in the instance diagram. In other words, it can only be a unidirectional link.

4. Composition synthesis is a special form of aggregation, which implies the lifetime responsibilities of "local" within "Overall. Synthesis is not shared. Therefore, although local data may not be destroyed as a whole, it is either responsible for local survival or destruction. It cannot be shared with other entities. However, ownership can be transferred to another object as a whole, and the latter will assume the responsibility for survival. The relationship between employee and timecard may be more suitable for "merging", rather than "associating ".

5. generalization indicates the relationship between a more generalized element and a more specific element. Generalization is a UML element used to model inheritance. In Java, the extends keyword is used to directly represent this relationship.

6. Implement (realization) an instance relationship specifying a contract between two entities. In other words, one entity defines a contract, and the other entity guarantees the performance of the contract. When modeling a Java application, the implementation relationship can be expressed directly by the implements keyword.

 

 

 

 

1. http://www.uml.org.cn/oobject/201104212.asp

2. http://www.cnblogs.com/riky/archive/2007/04/07/704298.html

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.