Tutorials to .com

Tutorials to .com » Php » Application » PHP and UML class diagrams: PHP and UML Class Diagrams

PHP and UML class diagrams: PHP and UML Class Diagrams

Print View , by: iSee ,Total views: 11 ,Word Count: 1075 ,Date: Sun, 24 May 2009 Time: 10:14 PM

This essay written by a good use php to interpret UML (or conversely) can be described as an innovation, and through this article, I also found a good point: www.phppatterns.com. The translation from UML terminology I am looking at the "UML User's Guide (The Unified Modeling Language User Guide)" the book.

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.

[Inheritance inheritance]

PHP keyword extends to allow a class (subclass) to inherit another class (parent class).

<? php
class Senior (

)

class Junior extends Senior (

)
?>


UML expressed as follows:




Please note that the triangle in the parent's side.

[Associations relationship]
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.

For example:

<? php
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:

<? 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.


[Messages News]

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.

<? php
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.

<? php
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.

[Resources 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


PHP Application Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.