The relationship between class and class diagram

I. Introduction

Class is a collection of objects to display the object's structure and interactions with the system. Class main attribute (Attribute) and method (Method) composition, properties represent the state of the object, if the property is saved to the database, this called the "persistence"; way representative of the operational behavior of objects, class inheritance, can be inherited in the parent class, you can also interact with other Class.

Class diagram shows the logical structure of the system, the relationship between classes and interfaces.

Second, the composition of class

There are properties and methods class composition. Such as product attributes are: name, price, height, width, etc.; commodities methods: calculation of tax rates, access to product evaluation and so on. As illustrated

The relationship between class and class diagram

Third, the relationship between classes (Relationship)

Association (Association)

Two relatively independent of the object, when an object instance with another instance of an object-specific fixed relationship exists, this association exists between the two object relations.

1, one-way association

A1-> A2: understanding that A1 A2, A1 aware of the existence of A2, A1 can call A2 in the methods and properties

Scene: orders and goods, including goods orders, but the goods do not understand the existence of orders.

Class and class one-way between the incidence graph of:

The relationship between class and class diagram

C # code:

Public class Order
Public List<Product> order;
Public void AddOrder(Product product )
Public Class Product

<script src="/ads/ads_250x250.js"></script>

Code performance :Order(A1) In Product(A2) The variable or reference

2. Bidirectional Association

B1-B2: Understanding that represents B1 B2,B1 Aware of the existence of B2 ,B1 You can call the B2 's methods and properties : Also know as B2 B1 In the present, the B2 can also call the B1 Methods and properties .

Scene : Orders and customers, orders belonging to a customer , The customer has some specific orders

Class and unidirectional associations between a class diagram


C# Code

Public class User
Public List<Order> GetOrder()
} return new List<Order>();
Public Class Order
Public User GetUserByOrderID(string OrderId )
Return new User();

3, self-association

With the association between a class object

Self-association between class and class diagram

The relationship between class and class diagram

4, multi-dimensional correlation (N-ary Association)

Correlation between the number of objects

Scene: The company employs the same time, companies need to pay wages to employees

Class and the class of multi-dimensional correlation map between:

The relationship between class and class diagram

5, generalization (Generalization)

Classes and class inheritance, relations between classes and interfaces.

Scene: Father and Son, animals and people, plants and trees, the system users and B2C relationship between members and B2E Member

Generalization between classes and the class diagram:

The relationship between class and class diagram

Users of the system include: B2C members, B2B and B2E Member Member

6, dependent on (Dependency)

Class A to complete a function must refer to class B, then A and B there is dependency, dependency is a weak association.

C # does not recommend the two-phase dependent, that is, each reference


Had no relationship between man and computer, but by chance, people need to write a computer program, this time people will rely on the computer.

Class and class dependency graph

Generally in the program using reference.

The relationship between class and class diagram

7, aggregation (Aggregation)

When the object A is added to the object B, as an integral part of the object B, object B and object A relationship between the aggregate. Aggregation is an association relationship is a strong correlation between stress the relationship between whole and part.

Scene: goods and his specifications, style is the aggregation relationship.

Class and the class diagram of polymerization

The relationship between class and class diagram

8, composite (Composite)

Object A contains object B, object B from object A has no real meaning. Is a stronger association. One contains hand, the hand leave the human body loses its proper role.

Scene: Window Forms from the slider slider, the head and work areas Header Panel combination.

Combination of class and class diagram

The relationship between class and class diagram

IV Summary

In this paper, the relationship between classes used a simple description, are: correlation, generalization, dependency, aggregation and composition.


<! - Page ->

分类:Development 时间:2010-04-07 人气:219
blog comments powered by Disqus


iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 闽ICP备15018612号

processed in 0.269 (s). 10 q(s)