UML class illustration

Source: Internet
Author: User

"By the way, I often see these class diagrams in some technical books. They are simple and easy to understand. I am confused with some labels. Otherwise, let me know ."

Laruence: "In fact, I am familiar with this. I will give you an example to look at this figure, which includes the basic graph method in the UML class diagram ."

UML class diagram example

Large
BIRD: "First, you can see the rectangular box of the 'animal '. It represents a class ). The class chart is divided into three layers. The class name is displayed at the first layer. If it is an abstract class, it is displayed in italic. The second layer is the class features,
Fields and attributes are usually used. The third layer is a class operation, usually a method or action. Note the preceding symbols. '+' indicates public, '-' indicates private, and '#' indicates public.
Protected ."

Laruence: "Then pay attention to the 'Flying 'in the lower left corner. It represents an interface graph. The main difference between it and a class graph is that the top graph is displayed <interface>. The first line is the interface name, and the second line is the interface method. There is another way to express the interface, also known as the lollipop notation, that is, the Donald Duck class implements the 'talking tal' interface ."

Side dish: "Why is it 'people talking '?"

Laruence: "ducks also have language, but only Donald Duck can speak human words ."

Side dish: "It makes sense ."

Laruence: "Next we will talk about the relationship between classes and interfaces. You can first pay attention to the relationship between animals, birds, ducks, and Donald Duck ."

"You understand, they are all inherited relationships. The Inheritance relationships are represented by hollow triangles + solid wires ."

Laruence: "among the several birds I raise, the geese are the most capable. I have made it an interface for flying. The implementation interface is represented by a hollow triangle + dotted line ."

Large
BIRD: "You see penguins and climate. Penguins are very special birds and they will not fly. More importantly, it is highly related to the climate. We will not discuss why there are no penguins in the Arctic, and why they need to make annual calls
Trek. In short, penguins need to know about climate changes and climate patterns. Association can be used when one class knows the other class ). Real-line arrow for Association
Header ."

Large
BIRD: "Let's take a look at the two types of geese and geese. Geese are group animals, each of which belongs to one group, and one group can have multiple geese. So aggregation is required between them.
(Aggregation) relationship. Aggregation indicates a weak 'owner' relationship. It indicates that object A can contain object B, but object B is not part of object a [DPE] (DPE indicates this sentence ).
From design patterns (2nd), see Appendix 2 for a detailed summary ). The aggregation relationship is represented by a hollow diamond + solid arrow ."

Large
BIRD: "composition (also translated into 'composite ') is a strong 'havn' relationship, reflecting the strict relationship between the part and the whole, the same as the overall Lifecycle
[DPE]. Here, birds and their wings form a synthetic (composite) relationship because they are partial and integral, and wings share the same life cycle as birds. Use solid diamond + solid arrow to form the compositing relationship
. In addition, you will notice that there is a number '1' and number '2' at both ends of the link of the compositing relationship, which is called the base number. It indicates that the class at this end can have several instances. Obviously, a bird should have two wings.
If a class may contain multiple instances, it is represented by 'n. Association and aggregation can also have a base ."

Class bird

{

Private wing;

Public bird ()

{

Wing = new wing ();

}

}

Laruence: "the major characteristics of animals, such as metabolism, can breed. Animals must have vitality and need oxygen, water and food. That is to say, animals depend on oxygen and water. They are dependent, expressed by the dotted arrow ."

Abstract class animal

{

Public metabolism (oxygen, water
Water)

{

}

}

"Ah, it seems that UML class diagrams are not difficult. Looking back at the code I wrote in my interview questions that day, I finally understood why I failed to write. I could have written such a wonderful code in a small calculator. Thank you, laruence ."

Laruence: "Hey, remember, programming is a technology and an art. You can't just finish the work after writing the code and running the results correctly. You often think about how to make the code more concise, easier maintenance and scalability
And reuse, only in this way can be truly improved. Writing elegant code is really a great thing. A uml class diagram is not a step-by-step process. There is no end to learning. In fact
This is the beginning of understanding object-oriented ."

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.