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.