Lompat ke konten Lompat ke sidebar Lompat ke footer

Uml Class Diagram Non Member Function

A UML class diagram is a structure diagram that describes the static structure of a system. The class diagram is a static modeling representation to describe the structure of the software system, which reflects the relationship between class structure and class. Classes in class diagrams correspond to the concepts of classes in object-oriented languages.

Class Notation

In the UML diagram of a class, a rectangle is used to describe the main components of a class, and the rectangle is vertically divided into three layers to place the name , attributes, and methods of the class .

As shown in the Figure above, a general class names are represented in normal font boldface, as shown above; abstract class names are in italic boldface, eg User ; interfaces need to be added at the top . <<interface>>

Attributes and methods all need to label visibility symbols, + represent public , # represent protected , and - represent private .

In addition, you can also use a colon to : indicate the type of the property and the return type of the method, such as , . Of course, the type description is not necessary. +$name:string+getName():string

Class relationships

There are six main types of relationships between classes: inheritance , realization / implementation , composition , aggregation , association, and dependency . The arrows for the six relationships are as follows:

Then we come to understand the specific content of the class relationship.

six types of relationships

In the six types of relationships, the code structure of the three types of relationships such as composition , aggregation , and association is the same as using attributes to store the references of another class. Therefore, they must be distinguished by the relationship between the contents.

Inheritance

Inheritance is also called generalization and is used to describe the relationship between parent and child classes. A parent class is also called a base class, and a subclass is also called a derived class.

In the inheritance relationship, the subclass inherits all the functions of the parent class, and the parent class has all the attributes, methods, and subclasses. Subclasses contain additional information in addition to the same information as the parent class.

For example: buses, taxis, and cars are cars, they all have names, and they can all be on the road.

The PHP code is implemented as follows:

public function __construct ()

public function __construct ()

echo $line2->name . $line2->run();

Realization / Implementation

Implementation (Implementation) is mainly used to specify the relationship between interfaces and implementation classes .

An interface (including an abstract class ) is a collection of methods. In an implementation relationship, a class implements an interface, and methods in the class implement all methods of the interface declaration.

For example: cars and ships are vehicles, and the vehicle is just an abstract concept of a mobile tool, and the ship and the vehicle realize the specific mobile functions.

Class Car implements Vehicle

return $this ->name . 'On the road' ;

Class Ship implements Vehicle

return $this ->name . 'Sail at sea' ;

Combination relationship

Composition: The relationship between the whole and the part, but the whole and the part cannot be separated .

The combination relationship represents the relationship between the whole and part of the class, and the overall and part have a consistent lifetime. Once the overall object does not exist, some of the objects will not exist, and they will all die in the same life.For example, a person is composed of a head and a body. The two are inseparable and coexist.

Public function setHead (Head $head)

Public function setBody (Body $body)

Public function display ()

return sprintf( 'man composed of %s and %s' , $this ->head->name, $this ->body->name);

$man->setHead( new Head());

$man->setBody( new Body());

Aggregation Relationship

Aggregation: The relationship between the whole and part, and the whole and part can be separated.

Aggregate relations also represent the relationship between the whole and part of the class, member objects are part of the overall object, but the member object can exist independently from the overall object.

For example, bus drivers and work clothes and hats are part of the overall relationship, but they can be separated. Work clothes and hats can be worn on other drivers. Bus drivers can also wear other work clothes and hats.

public $name = 'work clothes' ;

public $name = 'work hat' ;

Public function wearClothes (Clothes $clothes)

$this ->clothes = $clothes;

Public function wearHat (Hat $hat)

return sprintf( 'Bus driver wears %s and %s' , $this ->clothes->name, $this ->hat->name);

$driver->wearClothes( new Clothes());

$driver->wearHat( new Hat());

Relationships

Association: Indicates that a property of a class holds a reference to an instance (or instances) of another class .

Association is the most commonly used relationship between a class and a class, which means that there is a connection between one type of object and another type of object. Combinations and aggregations also belong to associative relations , but relations between classes of affiliations are weaker than the other two.

There are four kinds of associations : two-way associations , one-way associations , self-association , and multiple-number associations .

For example: cars and drivers, one car corresponds to a particular driver, and one driver can drive multiple cars.

In UML diagrams, bidirectional associations can have two arrows or no arrows , and one-way associations or self-associations have an arrow . The corresponding PHP code in the above figure is as follows:

public function addCar (Car $car)

public $drivers = array ();

public function addDriver (Driver $driver)

$this ->drivers[] = $driver;

$line1->addDriver($jack);

In a multiplicity relationship, you can add a number directly to the associated line to indicate the number of objects in the corresponding class.

  • m..n : at least m, at most n (m<=n)

Dependencies

Dependence: Assume that a change in class A causes a change in class B, then say that class B depends on class A.

In most cases, dependencies are reflected in methods of a class that use another class's object as a parameter .

A dependency relationship is a "use" relationship. A change in a particular thing may affect other things that use it, and use a dependency when it is necessary to indicate that one thing uses another.For example: The car relies on gasoline. If there is no gasoline, the car will not be able to drive.

public $type = 'gasoline' ;

public function beforeRun (Oil $oil)

return 'add' . $oil->add();

echo $car->beforeRun( new Oil());

Class Diagram - Order System

The class diagram below models a customer order from a retail catalog. The central class is the Order . Associated with it are the Customer making the purchase and the Payment . A Payment is one of four kinds: Cash , Check , Credit or Wire Transfer . The order contains OrderDetails (line items), each with its associated Item .

Image result for class diagram visual paradigm

Summary

Among the six types of relationships, the code structure of combination, aggregation, and association is the same, and it can be understood from the strength of the relationship. The order from strong to weak is: inheritance → implementation → composition → aggregation → association → dependency . The following is a complete UML diagram.

Class Diagram - Order System illustrated by Visual Paradigm

Unified Modeling Language (UML) Readling List

Source: https://uml.gitbook.io/learning-uml-with-visual-paradigm/class-diagram-tutorial

Posted by: borlandchloeoes.blogspot.com

Posting Komentar untuk "Uml Class Diagram Non Member Function"