Drawing UML Diagram class structure diagram with Visio (Advanced article)

Source: Internet
Author: User
Tags inheritance

the relationships between classes

Inheritance Relationship

An inheritance relationship is the most understandable relationship. The picture is like this. The object-oriented argument is the is-a relationship. That is to say Class2 is a Class1. In C + + we say that Class2 is a derived class of Class1, or that Class1 is the base class for Class2.

Aggregation and Composition

Start with a relationship that is easy to understand. There is often a case where a class is a data member of another class. Represented in UML, aggregation (aggregation) and composition (composition).

From the diagram, both of these relationships behave as a straight line with a diamond at one end. One end of the diamond is the whole, the other end is part. The difference is whether the diamond is hollow or solid. From C + + Zeng, if the picture Narimi Heart Diamond, CLASS1 will be responsible for the creation and destruction of Class2. More precisely, if Class1 does not exist, Class2 must not exist. For example like the following program.

Class Class2

{

};

Class Class1

{

Class2 M_objclass2;

}

And, of course, the following situation.

Class Class2

{

};

Class Class1

{

Class1 ();

~class1 ();

Class2* M_pclass2obj;

};

The declaration of a class cannot be seen. This is where you need to see the implementation part of the class.

Class1::class1 ()

{

M_pclass2obj = new Class1;

}

Class1::~class1 ()

{

Delete m_pclass2obj;

M_pclass2 = NULL;

}

Composition (composition) relationship, if the Class1 object is destroyed, such as code that does not destroy the data member in the destructor, then the relationship is a clustered (aggregation) relationship. Of course, there are many kinds of code that destroys data members.

Dependent Relationships

Dependency is the use of another class in a class. For example, the following code

Class1::dosomething ()

{

CLASS3 obj;

Obj. Doclass3work ();

}

This is the case. The picture is like this.

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.