UML class map introduction

xiaoxiao2021-03-06  63

First, UML introduction

UML (Unified Modeling Language), a unified modeling language, is an icon-based software design language published by Object Management Group.

UML function:

Visualization, description, construction, construction document

UML includes:

Use case (USE Case Diagrams)

Class Diagrams

Sequence Diagrams) (SEQUENCE DIAGRAMS)

Collaboration Diagrams

State chart (StateChart Diagrams)

Activity Diagrams

Component Diagrams)

Deployment Diagram (Deployment Diagrams)

(Blue is more important and commonly used)

Class diagrams are the most commonly used UML diagrams showing the static structure and relationship between class, interface, and between them; it is used to describe the structured design of the system.

The most basic element of the class diagram is class or interface.

Second, class diagram

Class (Class)

It is generally included in three components. The first is a class name; the second is attributes; the third is the method provided by this class (the nature of the class can be placed in the fourth part; if the class contains the internal class, the fifth composition will occur section). The class number is not omitted, and other components can be omitted.

Class name written specification: The status of the status of the status can be instantiated, and the oblique word describes the abstraction class.

Properties and Method Writing Specifications: Modifier [Description Information] Properties, Method Name [Parameters] [: Return Type | Type]

Attributes and methods can be attached to visibility modifiers:

The plus sign ( ) means public; minus (-) represents private; # 号 Represents protected; omitting these modifications indicate visibility with package (packet) level.

If the attribute or method has an underscore, it means it is static.

Description Information uses << opening and use >> ending.

The nature of the class is composed of an attribute, an assignment method, and a value method. Writing methods and methods are similar.

example 1:

Public Class Taxcalculator

{

PRIVATE Long Taxrate;

PRIVATE Long Salary;

Public Taxcalculator (long taxrate)

{

THIS.TAXRATE = TaxRate;

}

Public long counttax ()

{

Return Taxrate * Salary;

}

Public int getSalary ()

{

Return Salary;

}

Public void setsalary (int sale)

{

THIS.SALARY = SALARY;

}

}

Taxcalculator

-TaxRate: Long

Taxcalculator (A: long)

countTax (): long

SALARY: Long

2. Package

Package is a combination mechanism for conventional uses. One package in UML directly corresponds to a package in Java. In Java, a package may contain other packages, classes, or both. When modeling, logical packages are usually used to organize the model; use physical packages for converting the Java package in the system. The name of each package has a unique identifier for this package. example:

3. Interface (Interface)

The interface is a collection of operations, which specifies a service provided by a class. It corresponds directly to an interface type in Java. There are about two ways to interface. Specific paintings see examples:

example:

Public Interface Taxcalculator

{

Public long counttax ();

Public int getSalary ();

Public void setsalary;

}

Painting one:

Painting 2:

Interface

Taxcalculator

countTax (): long

GetSalary (): int

setsalary ()

4. Relationship

Common relationships are: generalization relationship, realization, aggregation relationship, synthetic relationship and dependencies. Note that different relationships differ in the connection between the figures.

4.1 Generalization Relationship (Generalization)

It is also called "generalization relationship" in some books and materials.

The general relationship represents the inheritance relationship between classes and classes, interfaces and interfaces. The arrow in the relationship is directed from the subclass to the parent class. In Java, use the extends keyword to directly represent this relationship.

example:

Public Abstract Class Employee {

}

Public class programer extends Employee {

}

4.2 Realization

The instance relationship specifies a contract between two entities. In other words, an entity defines a contract and another entity guarantees to fulfill the contract. The arrow in the relationship is directed by the class that implements the interface. In Java, implementation relationships can be represented directly with the Implements keyword.

example:

Public interface collegeprson {

}

Public Class Professor Implements CollegePerson {

}

A method 1: (Implementing under Rose2003, the connection line does not have an arrow, because the direction is obvious)

Method 2:

4.3 Association

Indicates connections between classes and classes. It makes a class of visible properties and methods by another class. The association can be two-way or unidirectional. The two-way associated arrow is an optional, one-way arrow points to the direction of traversal or query. In Java, the associated use instance variable is implemented. Additional counted numbers can be used to illustrate the number of corresponding numbers in the association relationship.

Base

meaning

0..1

Zero or one instance

0 .. * or *

No limit, arbitrary

1

Some and can only one example

1..*

At least one instance

Common base

Example: Take the user group in permissions, the user role as an example, one user role can belong to one or more user groups, and one user group can contain multiple user roles. If the user group uses the following method to get the permissions of the user role ...

PUBLIC CLASS UserGroup {

PRIVATE Userrole Urole;

......

}

Public class userrole {

}

Then behave in the figure: (pay attention to the painting of the arrow)

Note: An association relationship is often a polymeric relationship or a synthetic relationship.

4.4 aggregation (AGGREGATION)

The polymerization is a form of association, representing the overall / local relationship between two classes. The aggregation suggests that the overall concept is at a higher level than the local level, while the association suggests that both classes are conceptual at the same level. In Java, aggregation is also implemented using instance variables. The difference between associations and aggregates is purely conceptual, can't distinguish in Java grammar. The aggregation also implies that there is no loop in the example figure. In other words, it can only be a one-way relationship. Example: The relationship between cars and tires can say a good question.

Public class car {

Private tyres Tyres;

}

Public class tyres {

}

4.5 synthesis (Composition)

Synthesis is a special form of polymerization, suggesting "local" in "overall" survival duties. Synthetic relationships cannot be shared. Therefore, although local does not have to be destroyed with the overall destruction, the whole is either responsible for maintaining local survival status or is responsible for destroying it. Partially sharing with other overall sharing. However, the whole can turn all rights to another object, and the latter will follow the survival duties.

Example: People and his legs are a good example.

Public class man {

Private leggs legs;

}

Public class leggs {

}

4.6 Dependency

Dependence is also a connection between classes and classes, and relying on always one-way. A "use" relationship between the entity suggests that after the specification of an entity changes, it may affect other instances of it. More specifically, it can be converted to any type of reference to a class or object not in the instance scope. This includes a local variable that references an object of an object obtained by method call (as shown in the following example), or reference to a static method of a class (there is also an example of that class). It is also possible to use "dependence" to indicate the relationship between the package and the package. Because the package contains classes, you can represent the relationship between the package and packets according to the relationship between the various classes in those packages.

Example: When a payr is calculated, an example of using a calculator is used.

PUBLIC CLASS EMPLOYEEEE {

Public Void Calcsalary (Calculator Csalary)

{

}

}

Third, small knot

Here mainly introduces the details that may be encountered in reading and design class maps. hope that it can help us. Since the personal level is limited, it is not known to UML, OO, so there may be some problems and insufficient problems in the body, I hope everyone will correct it.

转载请注明原文地址:https://www.9cbs.com/read-85218.html

New Post(0)