A graph that lets you quickly learn UML (aggregation, composition, dependencies, inheritance, interfaces, classes)

Source: Internet
Author: User
Tags inheritance

A friend of the reflection, a direct talk about the design mode even if the understanding, and do not know how to draw a class diagram, then we will use a graph to illustrate how to apply UML to correctly represent the relationship between class and classes.

This picture tells the whole story about the survival of birds.

The first is the class: in UML, we use a rectangle that is divided into three columns. The first column is the name, the second column is the attribute, and the third column is the method.

Inheritance: Donald Duck belongs to one of the ducks, or the refinement of the Duck division, while the Ducks belong to birds, birds belong to animals, here, whether expressed as "yes" or belong to, is such an intuitive relationship. With a solid line at one end with a hollow triangular arrow. The arrow points to the parent class.

Dependence: All animals, survival needs water and air, this necessary demand, we call it dependency. With a dashed end with arrows, arrows pointing to dependencies.

Aggregation, combination: These two relationships we put together, because they seem to be very similar, but there are essential differences.

Many geese converge together into a flock of geese, it can also be said that there are geese in the wild, so is the relationship between the whole and the individual, that is, the relationship between the whole and the part is separable, they can have their own life cycle. Has-a That is, the wild geese may not exist, but the Dugu still exists.

A bird is a combination of two wings, that is, a bird has two wings. Although the combination and the aggregation we all say "has" what, but this "has" is different, he manifests is a kind of contains-a relations, this kind of relation is stronger than the aggregation, also is called the strong aggregation, he also manifests the whole and the partial relations, but at this time the whole and the part is not divided, The end of the whole life cycle means that part of the life cycle is over, such as the Bird is dead, and the two wings will not exist.

Association: Penguins are associated with climate, associations are the most common relationships that represent joins between classes and classes that enable one class to know the properties and methods of another class. An association has two endpoints, which can have a cardinality at each endpoint, indicating that the associated class can have several instances.
Common cardinality and Meaning: 0..1:0 or 1 instances.
0..*: There is no limit to the number of instances.
1: There can be only one instance.
1..*: There is at least one instance.

Interface: The end is the interface, the interface has two columns, the first column of the top Plus "interface" after the interface name, the second column is the interface method. The interface has its own representation "implementation", with a dashed end with a hollow triangle. In the actual development, in order to better realize the "open-close principle", it is generally defined interface, depends on the interface, depends on the abstraction.

There is also a concept-polymorphic, not appearing in the diagram. Polymorphism, as the name implies, has many forms.

Bush.roar ()

Orang.roar ()

Donald.roar ()

It is also a roar message, but because different objects can produce completely different results.

Above, is through a diagram to quickly understand UML, picture via "Big talk design mode", if there is insufficient, welcome treatise.

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.