Nine examples of UML illustrations

Source: Internet
Author: User
Tags dashed line
relationships among classes in UML diagrams: Dependency, generalization, association, aggregation, composition, implementationClass and Class Diagram 1) Class (class) encapsulates the data and behavior, is an important part of object-oriented, it is a collection of objects with the same properties, operations, relationships collectively. 2) in the system, each class has a certain responsibility, responsibility refers to the task of the class, that is, the class to complete what kind of function, what kind of obligations to bear. A class can have a variety of responsibilities, well-designed classes generally have only one responsibility, in defining classes, the responsibility of the class is decomposed into the properties and operations of the class (that is, methods). 3) The class's attribute is the data responsibility of the class, the class's operation is the class's behavior responsibility

I. Dependency relationship (dependence)

Dependency relationship (dependence): Assuming that Class A changes cause a change in class B, the name Class B depends on Class A.

• Dependency (Dependency) is a usage relationship in which a change in a particular thing can affect other things that use the thing and use dependencies when it is necessary to indicate that one thing is using another. In most cases, a dependency is embodied in a method of a class that uses an object from another class as a parameter. • In UML, a dependency relationship is indicated by a dashed line with arrows, and the relying party points to the relying party.       public class Driver {public void drive (car car) {car.move ();   } ...... }       public class Car {public void Move () {...} ...... }

There are three types of dependencies:

1. Class A is a local variable in class B (a method).

2. Class A is a parameter of class B method;

3. Class A sends messages to Class B, which affects the change of Class B;

ii. generalization Relationship (generalization)

Generalization relationship (generalization): A is the parent class of B and C, B,c has a public class (parent class) A, stating that A is a generalization (generalization, also known as generalization) of b,c

• Generalization relationships (generalization), also known as "is-a-kind-of" relationships, are used to describe the relationship between a parent class and a subclass, which is also known as a base class or superclass, and a subclass is also known as a derived class. In UML, the generalization relation is represented by a straight line with a hollow triangle. • When code is implemented, use an object-oriented inheritance mechanism to implement generalization relationships, such as using the extends keyword in the Java language, and using the colon ":" in c++/c#.

  public class person    {       protected  string name;       protected int age;        public void move ()         {            ......       }        public void say ()        {            ......       }  }   Public class  Student extends Person    {       private  string studentno;       public void study ()         {           ......        }   }  

In UML, there are three requirements for generalization relationships:

1, the subclass and the parent class should be exactly the same, the parent class has the properties, operations, subclasses should have;

2. In addition to the information that is consistent with the parent class, the subclass includes additional information;

3. Where instances of the parent class can be used, instances of subclasses can also be used;

Iii. Association Relationship (Association)

Association Relationship (Association): Relationships between classes, such as customers and orders, each order corresponds to a specific customer, and each customer corresponds to a specific order, such as the association between the basketball player and the team (shown below).

Among them, "employee" and "employer" on both sides of the association indicate the relationship between the two, and the number indicates the limitation of the relationship between the two, which is the multiplicity of the correlation. usually have "*" (means all, not limited), "1" (indicating there is only one), "0 ..."   (denotes 0 or more), "0,1" (for 0 or one), "n...m" (which means N to m), "m...*" (for at least m). • Association Relationship (association) is the most common relationship between classes and classes, and it is a structured relationship that is used to indicate that a class of objects is associated with another type of object. • In a UML class diagram, a solid line is used to connect the classes of the associated objects, and when implementing an association relationship using programming languages such as Java, C #, and C + +, the object of one class is typically used as a property of another class.   • You can label a role name on an association line when using a class diagram to represent an association relationship. 1) Bidirectional Association: By default, the association is bidirectional.

public class Customer {private product[] products;   ...... }       public class Product {private customer customer; ...... }

2) One-way Association: The Association of a class can also be unidirectional, and a one-way association is represented by a solid line with arrows.       public class Customer {private address address;      ...... } public class Address {

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.