Accumulate Kuibu, Poly stream------about UML class diagram

Source: Internet
Author: User
Tags dashed line

The existence of UML

Class diagram is a UML diagram with high frequency, which is used to describe the classes contained in the narrative system and the relationship between them, to help people to simplify the understanding of the system, is also an important product of the system analysis and design phase, but also the system coding and testing of the important type basis.


How to express UML


Its presentation method is also relatively simple, divided into three layers, the first layer is the class name. The second layer is the attribute, and the third layer is the method.

The "+" used in the properties and methods represents public, "-" denotes Private, "#" represents protected. And the notation of the property: the permission modifier, the property name (method name), and then the data type (or return value). These are basic grammar, and are more obvious and simpler.

There are, of course, representations of interfaces and abstract classes:

Used to describe the interface of narrative;

Used to describe abstract methods of narration.

the relationship between UML descriptive narrative class diagrams

There are four kinds of relationship between class diagram: Generalization relation, realization relation, dependency relation, association relation, and association relation is divided into common relation, aggregation relation and synthetic relation. But in fact these relationships we easy to understand, but many other times we have to pay attention to how to translate into Java code:

Generalization Relationshipsgeneralization relationship is essentially our inheritance, class inheritance and a class, this code should be better, we just need to remember the UML presentation method is good

(Pictures are reproduced from the Internet)It is important to note that the direction of the integration, the Hollow arrow plus implementation of the inheritance, the arrow pointing to who represents the successor. As for the Java relational code, the public class Tiger extends Animal () {}; Implementing Relationshipsthis is to be compared to the interface, descriptive narrative implementation interface, this we also come to the simple note:
(Pictures are reproduced from the Internet)as a control, similar to inheritance is the hollow arrow, and the inheritance is different from the dashed line is realized; The Java code here is the public class Penbrush implents Ibrush () {}; Dependent relationshipsPut the dependency on the third one. is because it is the lightest relationship between classes and classes. It can be one-way or two-way, but we usually use one-way. Avoid two-way.
(Pictures are reproduced from the Internet)
Dependency relationships are slightly more problematic to interpret than inheritance and implementation. As a result of inheritance and implementation we have been used frequently. and more singular. There is a clear hierarchy, and the dependency is not, just as people in the picture rely on computers to do certain things. Just as in "Big talk design mode" animals rely on air and water, air and water are separate things different from animals, like the computer is different from the human independent things, it is independent, and human in computing or other actions need to use the computer, just like the animal's breath needs air, water needs the same, It may be used in its behavior to have a separate existence. And assuming that this is not done, it may not be necessary to use this existence, like a dead animal that has no water or air, but it is still an animal, and this class will not change.

The explanation may be more troublesome, but the method is still very easy, a dashed line with a solid arrow is enough; As for the code implementation method. will require detailed treatment of the situation.

generally speaking, it can be expressed as: ①: The class being directed. In the class that points to it, it is the most common way to use the number of parameters as a method.

public class Person{public void count (computer computer) {}}
②: Can also be directed to the class. In the class that points to it. As a local variable in a method;
public class Person{public void count () {Computer computer=new computer ();}}
③: Another way is to have static methods in the class being directed. And the class that points to it calls its static method;
public class computer () {public       static void Test () {       }}public class person{computer.test ();}
Association relationship: The last is our relationship, saying that it is divided into three states: Ordinary Association, aggregation and synthesis, their greatest common is the relationship between, and the way the code appears to be pointed to the class as a pointer to the member variables appear, and we look at how they are different? General Association Relationship
(Pictures are reproduced from the Internet)
This is the most common correlation. The code is also very easy to write:
public class customer{  private address address. }
There are also self-associations and bidirectional associations, and all of these are made into member variables of the corresponding classes. Self-correlation makes their own, bi-directional associations with each other. Aggregation relationship Relationship It's like an old man telling a story, to know how many years it will take, the background of that era might make you understand more deeply. But the aggregation relationship is not the case, not only that the times caused this, but the protagonist may be in an organization, the people of that organization, he is the people in the organization. The organization is made up of people like him.


(Pictures are reproduced from the Internet)
Its descriptive narrative form is more a diamond than a simple association. The class where the diamond is located points to each other. It's code-writing, which is a lot more troublesome than a normal association:

public class car{   private engine engine, public   Car (engine engine) {       } public  void Setengine (engine Engine) {  }}
It will not only be pointed to the object as a member variable. The member object is also used as a constructor and as a parameter of the Set method or other business method.
Synthetic relationships, and others call it combinatorial relationships. It differs from the aggregation relationship because the associated objects are inherently together. It's like limbs to creatures. Just like numbers for calculations.
(Pictures are reproduced from the Internet)
Because of its homology, the diamond has become solid. and the corresponding program has changed:
public class head{   private Mouth Mouth;   Public Head () {       mouth=new mouth ();   }}
It is a direct instantiation of a member in the overall construction method.


Accumulate Kuibu, Poly stream------about UML class diagram

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.