Lecture
UML (Unified Modeling Language) - a unified modeling language is a graphic description language for object modeling in software development. UML is a generic language; it is an open standard that uses graphic notation to create an abstract model of a system called a UML model . UML was created to define, visualize, design, and document mainly software systems.
The use of UML is not limited to software modeling. It is also used to model business processes, systems design and display of organizational structures.
There are 13 official UML 2.0 diagrams, each of which represents a different representation of different aspects of the system:
But we are not going to immediately carry the brain on ourselves (we will do it gradually), so today we will talk only about one type of diagrams - class diagrams . And illustrate everything with examples in PHP.
A class diagram is a type of static structure diagram . It describes the structure of the system, showing its classes, their attributes and operators, and also the interrelationships of these classes. And so, let's start with examples:
Generalization shows that one of the two related classes ( subtype ) is a more particular form of the other ( supertype ), which is called a generalization of the first.
Graphically, generalization is represented by a line with an empty triangle for a supertype .
Diagram:
On PHP it will look like this:
It's simple. Go ahead. And we introduce a couple of definitions:
Communication is a simple relationship between objects. It is represented by a line connecting two or more object blocks . It is found on class or object diagrams. Communication is a special case of association.
An association is a family of connections of two or more classes. There are five types of associations. But two are most common: bidirectional and unidirectional.
associations.
Consider private options:
Aggregation - “has a” (to be part of) a case of association. Aggregation applies when one class must be a container of other classes. Moreover, the lifetime of the contained classes does not depend on the lifetime of the container class.
Those. in our example, the object of the Model class acts as a container. And if during the execution of the program it is destroyed, it will not affect the object of the DataBase class.
Graphically, the aggregation is represented by an empty diamond on the class block and a line from this diamond to the contained class .
Diagram:
Code:
db = $db; } public function getAll() { return $this->db->selectAll(); } } ?>
Another “has a” association case, but more stringent. Unlike aggregation, a composition has a hard dependency of the lifetime of instances of a container class and instances of contained classes. If the container is destroyed, all its contents will be destroyed as well.
Graphically presented as an aggregation, but with a filled diamond .
Diagram:
PHP code:
helper = new Helper(); } public function render() { $this->page = $this->helper->fetch(); } } ?>
The difference between these two types of association is that the composition can be part of one and only one whole, while aggregation can be part of several objects.
A message is used when one class communicates with another through instantiation.
Instantiation (English instantiation) - the creation of a class instance. In contrast, the word “creation” is applied not to an object, but to a class. That is, they say to create a class instance or instantiate a class. Generating patterns use polymorphic instantiation.
An instance of a class is a description of a specific object in memory. The class describes the properties and methods that will be available for the object constructed according to the description laid down in the class. Instances are used to represent specific real world entities.
Graphically represented as an arrow directed to the “called” class .
Diagram:
PHP example:
page = HtmlUtils::specialChars($text); //....... } } ?>
The same directional association may be two-way, for example:
Diagram:
Code:
errorMsg; } } class View { public $errorMsg = 'Message'; public function someFunction() { //Тело функции и если возникает ошибка то $error = 1 if ($error) Debug::display(); } } ?>
That's all. Maybe if I am too lazy, I will write a few more articles on design, but for now I am waiting for your comments.
Z. Y. All charts were made in the program StarUML. Very easy and simple program, just what a beginner needs.
Comments
To leave a comment
Running server side scripts using PHP as an example (LAMP)
Terms: Running server side scripts using PHP as an example (LAMP)