PHP and UML class diagrams: PHP and UML Class Diagrams
UML (Unified Modeling Language, Unified Modeling Language) is a map of the way through the software system. Essence, it allows us to design through drawing our procedures and if the corresponding tools, we can even directly from the plan that generated the code. In this article, we will look at how PHP code by using the UML class diagram (class diagram) of ways.
We will start with the assumption that you have knowledge of UML and some examples of PHP code and their corresponding UML said that as an example - but it is not on the class diagram of a complete analysis.
If you have not yet come into contact with UML, in the reading before you begin to add some knowledge, we have collected a number of resources listed in the end of this article.
PHP keyword extends to allow a class (subclass) to inherit another class (parent class).
class Senior (
class Junior extends Senior (
UML expressed as follows:
Please note that the triangle in the parent's side.
Association (Associations) occurred in the relationship between the two does not exist but may need to visit each other between classes, such as the Model (Model) and the View (the view), View the need to provide data for Model show. There are several different types of relevance:
* Aggregation * aggregate
Aggregation (Aggregation) is a class (the following example for the Model) to access another type (the following example for Dao), the second category (Dao) may have been examples of external ($ dao) of the. If the first object ($ model) "hung up", the second object ($ dao) will continue to "alive." This is in relation to data access objects (data access objects) are common when they may be passed on to many objects, these objects even if "hung up" data access object still "alive."
Normal in this way to explain the first type (Model) The second type of control (Dao) part.
class Dao (
function getSomething () (
class Model (
var $ dao;
function Model (& $ dao) (
$ this-> dao = & $ dao;
function doSomething () (
$ this-> dao-> getSomething ();
$ dao = new Dao;
$ model = new Model ($ dao);
$ model-> doSomething ();
Expressed in UML as follows:
Category in the control of diamond-shaped hollow here.
* Composition * portfolio
Portfolio (Composition) occurred when in a category (for example View) to another category (for example LinkWidget) examples of such current are (View) "hung up" when the latter () is also followed by "finish off" situation.
In other words, the first type of control of the second category of all.
The following is an example in PHP:
class LinkWidget (
function display () (
class View (
var $ linkWidget;
var $ page;
function View () (
$ this-> linkWidget = new LinkWidget;
function renderPage () (
$ this-> page = $ this-> linkWidget-> display ()
The chart used in the UML, said:
In the control of diamond-type solid side.
Message (Messages) occurred in a class (for example of View) with other categories (for example HtmlUtils) "exchange" rather than control it (HtmlUtils) examples of the time. The relationship between these classes is the same relationship (association).
Usually occurs in PHP in the operator:: the use of the time. For example:
Annotation: I think in this way is similar to c + + in the HtmlUtils class member functions unHtmlEntities () for the static situation, so no need to instantiate can be directly HtmlUtils "class name:: member function names" approach (HtmlUtils:: unHtmlEntities ()) to call a.
class HtmlUtils (
function unHtmlEntities ($ str) (
$ trans_tbl = get_html_translation_table (HTML_ENTITIES);
$ trans_tbl = array_flip ($ trans_tbl);
return strtr ($ str, $ trans_tbl);
class View (
function renderPage (
$ text = HtmlUtils:: unHtmlEntities ($ text);
This will be expressed as:
View the message sent from HtmlUtils. (Send a one-way)
Similarly, two-way information can be sent.
class Debug (
function display () (
echo ($ this-> 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: "This is an error message"]
SomeClass here to send a message to the Debug, Debug visited $ errorMsg attribute of SomeClass.
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
PHP Application Articles
- Comparison of difference between the two dates a few days
- How to obtain the current time
- Getting Started with PHP String Manipulation Tutorial
- PHP / MySQL on the 3rd pass - first day (2)
- How to speed up your PHP program
- PHP scripts eight skills (5)
- PHP scripts eight skills (7)
- PHP Security Configuration (2)
- PHP through the Web in the implementation of C / C + + applications
- php generic test function set (5)
- Upload files using PHP
- An imitation oso forum program (bis)
- PHPLIB and multiple databases
- Php4 to accelerate the use of web transmission
- PHP Coding Practices (2)
- High skills of dozens of PHP
- PHP dynamic change of GB encoding UTF-8 encoding methods evaluation
- Examples of learning PHP template FastTemplate article
- A realization of the UBB with PHP type!
- PHP Counter
Can't Find What You're Looking For?
Rating: Not yet rated