This short article is well written. it can be said that using PHP to explain UML (or conversely) is an innovation. through this article, I also found a good site: www.phppatterns.com. The translation of various UML terms comes from the book I am reading, TheUnifiedModelingLanguageUserGuide. UML (UnifiedModelingLanguage) is a good short article. using PHP to explain UML (or to put it back) can be said to be an innovation. through this article, I also found a good site: www.phppatterns.com. The translation of various UML terms comes from The book "The Unified Modeling Language User Guide" I am reading.
UML (Unified Modeling Language) is a mechanism for expressing software through graphs. Essentially, it allows us to design our program through drawing, and if there is a corresponding tool, we can even directly generate code from the graph. In this article, we will look at how PHP code is presented by using the UML class diagram.
We will start directly, assuming that you have the knowledge of UML, and list some PHP code and their corresponding UML representation as an example -- but this is not a complete analysis of the class diagram.
If you have not been familiar with UML, you can add some knowledge before you start reading it. we have collected some resources listed at the end of this article.
[Inheritance relationship]
The PHP keyword extends allows one class (subclass) to inherit from another class (parent class ).
Class Senior {
}
Class Junior extends Senior {
}
?>
The UML method is as follows:
Note that the triangle is in the parent class.
[Associations Association]
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 the Model to provide data for display. There are several different Association types:
* Aggregation
Aggregation: when a class (Model in the following example) accesses another class (Dao in the following example), the second class (Dao) may have been instantiated externally ($ dao). If the first object ($ model) is "down", the second object ($ dao) will continue to "live ". This is common when it comes to data access objects, which may be passed to many objects. even if these objects are "hung", the data access objects are still "healthy ".
This method normally explains part of the first class (Model) controlling the second class (Dao.
For example:
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 ();
?>
In UML, it is represented:
The hollow diamond is in the control class.
* Composition * combination
Composition occurs when another class (LinkWidget in this example) is instantiated in one class (View in this example), so that when the former (View) is "hung", the latter () it also follows the "playing" situation.
In other words, the first class controls all of the second class.
The following is an example in PHP:
Class LinkWidget {
Function Display (){
}
}
Class View {
Var $ linkWidget;
Var $ page;
Function View (){
$ This-> linkWidget = new LinkWidget;
}
A message occurs when a class (View in this example) "communicates" with other classes (HtmlUtils in this example) and does not control its (HtmlUtils) instances. The relationships between these classes are also association ).
In PHP, the operator: used. For example:
I think this method is similar to the case where the unHtmlEntities () member function in the HtmlUtils class in C ++ is static, so that you can directly use the class name without instantiating HtmlUtils :: the member function name (HtmlUtils: unHtmlEntities () is called.
Here, SomeClass sends a message to Debug. Debug accesses the $ errorMsg attribute 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
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.