Four types of relationships in UML and four types of UML

Source: Internet
Author: User

Four types of relationships in UML and four types of UML

1. Association

Description: Assocition: Describes the structural relationship between two or more classes.

(1) Common Association:

1) Association name: used to describe the nature of the link.

2) Role: When a class is at one end of the Association, the class plays a specific Role in the relationship; A role is the responsibility of a class close to one end of the Association to present classes at the other end.

3) Multiplicity multiple: the multiple associated roles indicate the number of connected objects in an associated instance.

For example ():

 

Public Class Person

Private employer As Company

End Class



Public Class Company

Private employee As Person

'……

End Class

 

 

For example:

Public Class CatalogEntry

Private name As String

Private number As Integer

Private cost As Double

Public Function getCost() As Double

Return cost

End Function

End Class
Public Class Part

Private entry As CatalogEntry

Public Function Cost() As Double

Return entry.getCost

End Function

End Class



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim screw As New CatalogEntry("screw", 28834, 0.02)

Dim screw1 As New Part(screw)

screw1.Cost()

'……

End Sub

 

In the two examples above, the first is a two-way normal Association, and the second is a one-way Association. Likewise, two classes can have multiple associations, one class can be associated with multiple classes, and the other class can be associated with itself.

(2) aggregate aggregation

Note: Aggregation indicates A weak "ownership" relationship, which indicates that object A can contain object B, but object B is not part of object.

Example:

Public Class GooseGroup

Private arrayWildGoose As New WildGoose()

'……

End Class

 

(3) composition

Note: A strong "ownership" relationship represents a strict part and the overall life cycle is the same.

For example:

Public Class Bird

Private wing As Wing

Public Sub New ()

Wing = New Wing () 'in the bird class, the Wing wing Wing is instantiated during initialization, and both of them are generated at the same time.

End Sub

End Class

 

Ii. Generalization generalized relationship

Note: It is a special/general relationship. Objects of special elements (child elements) can replace objects of general elements (parent elements. In this way, the child element shares the structure and behavior of the parent element.

Representation Method:

Public Class Dog : Inherits Animal

'……

End Class

 

NOTE: If VB.net indicates that a class is no longer inherited, you can use notInheritable.

Iii. Dependency

Dependency:

For example:

Note: animals have several major features, such as metabolism and reproduction. Animals must have vitality and need oxygen, water and food. That is to say, animals depend on oxygen and water. Dependency between them, expressed by the dotted arrow

For example:

Public Class Professor

Public Function Teach(ByVal c As Course)

'……

End Function

End Class

 

NOTE: If two classes have a structural relationship (association relationship), there is no dependency relationship (two things generally have this relationship)

 

IV. Implementation of Realization

Note: Implementation refers to the semantic relationship between class elements. In this relationship, one class element describes the contract implemented by another class Element guarantee.

Representation Method:

Public Interface IShape

Function Draw()

End Interface



Public Class Circle : Implements IShape

Public Function Draw() Implements IShape.Draw

End Function

End Class

 

 

 

 

 

 

 

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.