Java design pattern--UML class diagram

Source: Internet
Author: User
Tags dashed line

2016-06-07 22:46:16

The following is a brief introduction to UML Class Diagram: (figure is intercepted, you can use the UML tools to draw)

1. Class diagram describing class

Class: Person

Property: Name Age Sex

Access rights:-Private +: Indicates public protected: represents

Method: GetName (): String SetName (name:string) getage (): int setage (Age:int) Getsex (): String Setsex (sex:string)

The last method followed is the return type, no return type is void, for example getname () The return type is String,setname (name:string) The return type is void

where SetName (name:string), Setage (Age:int), Setsex (sex:string) also contain parameter names and argument types

2. Abstract class

It can be seen that the class name car is italic, that the class is abstract, and that the method name driver is also italic, and that the method is abstract.

3. Interface

Interface ifly{    void  Fly ();

Interface ilanguage{    void  Speak ();}

4. Objects

Relationships in a class diagram:

1. Inheritance or generalization (generalization)

Note that a hollow triangle + solid line is used to connect

2, the realization of the relationship (realization)

Note that it is connected with a hollow triangle + dashed line

3. Association Relationship (Association)

Note that it is connected with a solid arrow, more accurately this is a directional association (directedassociation), the Association (association) is represented by a solid line, no arrows

Affinity: A class is able to "see" Properties and Methods in another class: drivers need to know the car's information, driver can see car, driver class has a reference to car class; Penguins trek every year, need to know climate change, The climate object of the climate is quoted in Penguin Penguin.

4. Aggregation relationship (aggregation)

Note that the Hollow Diamond + solid Line (arrow) is used to connect

The aggregation relationship is stronger than the association relationship, it is the relationship between the whole and the individual, and represents a weak ownership relationship, which shows that a object can contain a B object, but B object is not part of a object.

The car had to have an engine and a tyre, and a car wouldn't have just one tyre, so the car used an array when referencing tire.

5. Synthetic relationship (composition)

Note that the solid Diamond + solid Line (arrow) is used to connect

The synthesis relationship is stronger than the aggregation relationship, is a strong ownership relationship, embodies the strict relationship between the whole and the part, it requires that the general aggregation relationship represents the whole object is responsible for representing the life cycle of the part of the object, or their life cycle.

class bird{    private  Wing wing;      Public Bird () {        Wing=new  Wing ();         // in the Bird Bird class, when initialized, the wing Wing is instantiated, and both of them generate     }}

6. Dependency relationship (Dependency)

Note that a dashed arrow is used to indicate

Dependency is always one-way, which means that a class (a) relies on another class (b), and class B is used as a parameter by Class A in a methods method, and you can see that there are car and house parameters in the Buy method of the man class.

A more vivid example is that animals rely on oxygen and water

Abstract class animal{    public  metabolism (Oxygen oxygen,water water) {   
}}

Java design pattern--UML class diagram

Related Article

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.