Basic knowledge of UML class diagrams

Source: Internet
Author: User
Document directory
  • A class is a collection of objects. It shows the structure of an object and its interaction with the system. A class consists of attributes and Methods. attributes represent the state of an object. If an attribute is saved to a database, this is called persistence. Methods represent the operation behavior of an object, the class has an inheritance relationship. It can inherit from the parent class or interact with other classes.
  • The class diagram shows the logical structure of the system, and the relationship between classes and interfaces. A class chart shows how different entities (people, things, and data) are related to each other and shows the static structure of the system. Class diagrams can be used to represent logical classes. Logical classes are usually the types of things that business personnel talk about, such as rock bands, CD, and radio dramas, or abstract descriptions of loans, housing mortgages, vehicle credit and interest rates. Class diagrams can also be used to represent implementation classes. Implementation classes are the classes to be compiled by programmers. Implementation class diagrams and logical class diagrams may be used to describe some of the same classes. However, implementation class diagrams and logical class diagrams do not use the same description attributes.
  • A class chart is a rectangle divided into three parts. The top part shows the class name, the middle part shows the class attributes, and the bottom part shows the class operations (or "methods "). In fact, the most common and simple class diagram is a rectangle displaying the class name in it, because in UML, most classes only need a name that can be clearly expressed.
  • The type of the property or method parameter is displayed immediately after the colon (:) of the Parameter Name of the property or method. The Return Value Type of the method is displayed after the colon following the method.
  • Class consists of attributes and methods. For example, the product attributes include name, price, height, and width. The product methods include calculating tax rates and obtaining product reviews. For example
  • Association)
  • Two relatively independent objects. When an object instance has a fixed relationship with a specific instance of another object, the two objects are associated.
  • A1-> A2: indicates that A1 knows A2 and A1 knows existence of A2. A1 can call methods and attributes in A2.
  • Scenario: orders and commodities include commodities, but goods do not know the existence of orders.
  • Unidirectional association between classes:
  • C # code:
  • Public class order
  • {
  • Public list <product> order;
  • Public void addorder (product)
  • {
  • Order. Add (product );
  • }
  • }
  • Public class product
  • {
  • }
  • B1-B2: B1 knows B2, B1 knows the existence of B2, B1 can call the method and attribute in B2; B2 also knows the existence of b1, b2 can also call the method and attribute of B1.
  • Scenario: orders and customers. Orders belong to customers and customers have specific orders.
  • Bidirectional association between classes
  • C # code
  • Public class user
  • {
  • Public list <order> getorder ()
  • {
  • } Return new list <order> ();
  • }
  • Public class order
  • {
  • Public user getuserbyorderid (string orderid)
  • {
  • Return new user ();
  • }
  • }
  • Association between the same class object.
  • Association diagram between classes:
  • Multiple objects are associated.
  • Scenario: The company employs employees, and the company needs to pay wages to employees.
  • Multidimensional Association between classes:
  • The inheritance relationship between classes and interfaces.
  • Scenario: Relationship between father and child, animals and people, plants and trees, system users and B2C members, and b2e members
  • Generalization diagram between classes:
  • Users of the system include B2C members, B2B members, and b2e members.
  • The implementation of interfaces enables animals to eat, while humans are a specific instance of animals to implement specific eat actions.
  • Class A must reference Class B to complete a function. Class A has a dependency with Class B, and the dependency is weak. C # Two-Phase dependency is not recommended, that is, mutual reference
  • Scenario: people have nothing to do with computers, but due to occasional opportunities, people need to use computers to write programs. At this time, people rely on computers.
  • Dependency relationship between classes
  •  
  • It is generally referenced by using in a program.
  • When object A is added to object B and becomes an integral part of object B, object B and object a are aggregated. Aggregation is a type of association. It is a strong association, emphasizing the relationship between the whole and the part.
  • Scenario: The product has an aggregation relationship with its specifications and styles.
  • Aggregation relationship between classes
  • Object A contains object B, and object B leaves object. Is a stronger association. If a person contains a hand, his hand will lose its role when he leaves his body.
  • Scenario: The Window form is composed of slider, header, and workspace panel.
  • Relationship between classes and Classes
  • ------
  • P.s.
  • There are two types of has-a relationships. An object can have another object, and the latter is treated as a part of its own. The former is called aggregation (hollow diamond), and the latter is called inclusion/combination (solid diamond ). The party that owns the object is the side that the diamond is attached. The number next to the class. For example, 0 .. 1 indicates 0 or 1 objects of the class. For other examples, 0... *, 4... 5.
  • ----
  • UML interaction Diagram

From: http://www.cnblogs.com/millen/archive/2010/03/11/1683221.html

1. The overview class is a collection of objects, showing the object structure and interaction with the system. A class consists of attributes and Methods. attributes represent the state of an object. If an attribute is saved to a database, this is called persistence. Methods represent the operation behavior of an object, the class has an inheritance relationship. It can inherit from the parent class or interact with other classes. The class diagram shows the logical structure of the system, and the relationship between classes and interfaces. A class chart shows how different entities (people, things, and data) are related to each other and shows the static structure of the system. Class diagrams can be used to represent logical classes. Logical classes are usually the types of things that business personnel talk about, such as rock bands, CD, and radio dramas, or abstract descriptions of loans, housing mortgages, vehicle credit and interest rates. Class diagrams can also be used to represent implementation classes. Implementation classes are the classes to be compiled by programmers. Implementation class diagrams and logical class diagrams may be used to describe some of the same classes. However, implementation class diagrams and logical class diagrams do not use the same description attributes. A class chart is a rectangle divided into three parts. The top part shows the class name, the middle part shows the class attributes, and the bottom part shows the class operations (or "methods "). In fact, the most common and simple class diagram is a rectangle displaying the class name in it, because in UML, most classes only need a name that can be clearly expressed. You can also display the class construction type in the class name section. The constructor of the class is displayed between a pair of double-angle characters, including the symbol "»", and is often placed on the class name. Common constructor types include implementation class (direct display class name), interface (display "interface" on the class name), and tool class (display "utility" on the class name »). If the class name is in italic or {abstract} is marked under the class name, this class is an abstract class. There is a character before attributes and methods to indicate the scopes of attributes or methods. Their meanings are as follows: -"-" Indicates that the property or method is private ); -"#" Indicates that the property or method is protected (protected ); -"+" Indicates that the property or method is public ).The type of the property or method parameter is displayed immediately after the colon (:) of the Parameter Name of the property or method. The Return Value Type of the method is displayed after the colon following the method. 2. The main components of a class are attributes and methods. For example, the product attributes include name, price, height, and width. The product methods include calculating tax rates and obtaining product reviews. For example, 3. relationship association between classes two relatively independent objects. When an object instance has a fixed relationship with a specific instance of another object, the two objects are associated. 1 , Unidirectional Association A1-> A2: indicates that A1 knows A2 and A1 knows the existence of A2. A1 can call the method and attribute scenario in A2: Order and product. The order includes product, however, products do not understand the existence of orders. Unidirectional association between classes: C # code: public class order {public list <product> order; Public void addorder (product) {order. Add (product) ;}} public class product {} The Code is as follows: Order (A1) contains a variable or reference of product (A2 ). 2 , Bidirectional Association B1-B2: B1 knows B2, B1 knows the existence of B2, B1 can call the method and attribute in B2; B2 also knows the existence of b1, b2 can also call the method and attribute of B1. Scenario: orders and customers. Orders belong to customers. Customers have two-way Association diagrams between specific order classes and classes. C # code public class user {public list <order> getorder () {} return new list <order> ();} public class order {public user getuserbyorderid (string orderid) {return new user ();}} 3 , Self-Association Association between the same class object. Association diagram between classes: 4 Multi-dimensional Association (N-ary Association) Multiple objects are associated. Scenario: The company employs employees, and the company needs to pay the salary to the multi-dimensional association diagram between the employees and classes: 5 , Generalization (Generalization) The inheritance relationship between classes and interfaces. Scenario: A general diagram of relationships between parent and child, animals and people, plants and trees, system users and B2C members, and b2e members: Users of the system include B2C members, B2B members, and b2e members. The implementation of interfaces enables animals to eat, while humans are a specific instance of animals to implement specific eat actions. 6 , Dependency (Dependency) Class A must reference Class B to complete a function. Class A has a dependency with Class B, and the dependency is weak. C # Two-Phase dependency is not recommended, that is, mutual reference scenario: people have nothing to do with computers, but due to occasional opportunities, people need to use computers to write programs, at this time, people rely on computers. The dependency relationship between a class and a class is generally referenced by using in a program. 7 , Aggregation (Aggregation) When object A is added to object B and becomes an integral part of object B, object B and object a are aggregated. Aggregation is a type of association. It is a strong association, emphasizing the relationship between the whole and the part. Scenario: The product has an aggregation relationship with its specifications and styles. Aggregation relationship between classes 8 , Combination ( Composite ) Object A contains object B, and object B leaves object. Is a stronger association. If a person contains a hand, his hand will lose its role when he leaves his body. Scenario: The Window form is composed of slider, header, and workspace panel. There are two relationships between classes and classes ------ p.s. Has-a. an object can have another object, and the latter as/is not a part of itself. The former is called aggregation (hollow diamond), and the latter is called inclusion/combination (solid diamond ). The party that owns the object is the side that the diamond is attached. The number next to the class. For example, 0 .. 1 indicates 0 or 1 objects of the class. For other examples, 0... *, 4... 5. Iv. Summary This article briefly describes common relationships among classes, including Association, generalization, dependency, aggregation, and combination. ---- UML interaction Diagram

Each rectangle at the top represents a specific object.

The box at the top shows the name of the class (right of the colon) and the name of the object (left of the colon ). The "Object: Class" symbol indicates an object instantiated from the class. Eg. shape1: Square

A vertical line indicates the lifetime of an object.

A horizontal line that crosses a vertical line indicates the information that an object transmits to other objects.

Sometimes the return of a value or object is explicitly expressed, and sometimes it is only assumed by the user to return the result.

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.