Home >Backend Development >PHP Tutorial >PHP and UML class diagramsPHPandUMLClassDiagrams_PHP tutorial

PHP and UML class diagramsPHPandUMLClassDiagrams_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:26:091004browse

This short article is well written. Using PHP to explain UML (or vice versa) can be said to be an innovation. Through this article, I also found a good website: www.phppatterns.com. The translation of each UML terminology comes from the book "UML User Guide (The Unified Modeling Language User Guide)" that I am reading. UML (Unified Modeling Language, Unified Modeling Language) is a mechanism for representing software through diagrams. Essentially it allows us to design our programs by drawing pictures, and if the corresponding tools are available, we can even generate code directly from the pictures. In this article, we will look at how PHP code is represented using UML class diagrams. We will start directly, assuming you already have knowledge of UML, and give some PHP code and their corresponding UML representation as examples - but this is not a complete analysis of class diagrams. If you haven't been exposed to UML yet, you can add some knowledge before you start reading. We have collected some resources and listed them at the end of this article. [Inheritance inheritance relationship] The PHP keyword extends allows one class (subclass) to inherit from another class (parent class). UML representation is as follows: Please note that the triangle is on the parent class side. [Associations] Associations occur between two classes that do not have a relationship but may need to access each other, such as Model and View. View requires Model to provide data for display. There are several different types of associations: *Aggregation* Aggregation (Aggregation) is when one class (Model in the following example) accesses another class (Dao in the following example), the second class (Dao) may have been externally instantiated ($dao). If the first object ($model) "dies", the second object ($dao) will still continue to "live". This is common when it comes to data access objects (data access objects), which may be passed to many objects, and these objects are still "alive" even if the data access object "dies". This way it is normally explained that the first class (Model) controls part of the second class (Dao). For example: dao=& $dao; } function doSomething () { $this->dao->getSomething(); } } $dao=new Dao; $model=new Model($dao); $model ->doSomething(); ?> is represented in UML as: The hollow diamond is on the control class side. *Composition* Composition occurs when one class (View in the example) instantiates another class (LinkWidget in the example), so that when the former (View) "hangs" the latter () also follows. A "game over" situation. In other words, the first class controls everything of the second class. The following is an example in PHP: linkWidget=new LinkWidget; } function renderPage () { $this->page=$this->linkWidget->display() } } ?> It is represented by the following figure in UML: The solid diamond is on the control side. [Messages] Messages occur when a class (View in the example) "communicates" with another class (HtmlUtils in the example) without controlling its (HtmlUtils) instance. The relationship between these classes is also an association. In PHP this usually happens when the operator :: is used. For example: Translation Note: I think this method is similar to the case where the member function unHtmlEntities() in the HtmlUtils class in C++ is static, so that there is no need to instantiate HtmlUtils and you can directly use the "class name::member function name" method (HtmlUtils ::unHtmlEntities()) to call. This will be expressed as: The message is sent from View to HtmlUtils. (One-way sending) Similarly, messages can also be sent in both directions. errorMsg); } } class SomeClass { var $errorMsg=This is an error message; function someFunction () { if ( DEBUG == 1 ) { Debug::display(); } } } define (DEBUG,1) ; $someClass= &new SomeClass; $someClass->someFunction(); ?> [Output message: "This is an error message"] Here SomeClass sends a message to Debug, and Debug accesses the $errorMsg property of SomeClass. [Resources] Introduction to UML from the Object Management Group Posideon UML - a tool for drawing UML diagrams and generating Java (sadly no PHP), the community edition being free to use. Based on Argo UML, an open source project. Object Mentor on UML A UML Reference Card

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531980.htmlTechArticleThis short article is well written. Using PHP to explain UML (or vice versa) can be said to be an innovation. , through this article, I also found a good site: www.phppatterns.com. Various UML techniques...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn