Monday, December 15, 2008

Beef Heifers Cows For Sale

Generating PHP code from UML and UML

Creative Commons License

This work under a Creative Commons license .

© 2008 Jaime M. Tan Nozawa. You are free to copy, distribute and transmit the work and make derivative works under the following conditions: a) You must give the original author. b) can not use this work for commercial purposes (including publication by any means, for-profit entities). c) If you alter, transform this work or creates a derivative work, distribute the work only under a license identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of these conditions can be waived if you get permission from the owner of the copyright. The fair use rights or other constraints are not affected by the above. Full license Castilian. The information contained in this document and the derivatives thereof are provided as they are, the authors assume no liability if the user or reader of these misuses. Continuing


article UML CASE tool for PHP 5, we shall now see the creation of code from a class diagram of two tools: BoUML and ArgoUML.

Index Sections:
  1. Reviewing code generation
  2. Reviewing partnerships between classes
    1. Unit
    2. simple Association
    3. Association of aggregation and composition
    4. generalization Association

1) Reviewing code generation








Class created in ArgoUML / class created in BoUml

Cart has a class, but different tools. Let's look at the generated code

>> Code generated BoUML <<
can verify the following: We
  • generating PHP class name with the same name as in the UML
  • IMPORTANT: There is a comment tags / / Bouml preserved body begin / end which will avoid over-writing of your deployments once you've generated your code
  • Detected
  • good initialization of an attribute and visibility
  • the folder is created by package where (after configuration)
  • PROBLEM: Return values \u200b\u200bare always null, despite having specified integer or string.
  • PROBLEM: a comment is created, but it says the datatype of the attributes, method parameters or visibility.
 \u0026lt;? 

php / ** * Class
Cart
* / class Cart {

/ ** * Items
in carrito
*/
private $cantidad = 0;

/**
* Contructor
*/
public function __construct()
{
// Bouml preserved body begin 0001F503

$return=NULL;

return($return);
// Bouml preserved body end 0001F503
}

public function count()
{
// Bouml preserved body begin 0001F583

$return=NULL;

return($return);
// Bouml preserved body end 0001F583
}

public function guardar()
{
// Bouml preserved body begin 0001F603

$return=NULL;

return($return);
/ / Bouml 0001F603
preserved body end}}


?>

>> generated code in ArgoUML <<
can verify the following:
  • see that name is generated PHP class with long-form style, with separate underline (_) and as a prefix to the original name in UML
  • a comment is created PHPdoc style, it performed excellently documenting almost everything. Even the creator, dates and other minutiae.
  • has a similar comment tags to BoUML, allowing avoid over-writing of your deployments once you've generated your code
  • The return values \u200b\u200bare detected, even you make a cast of the variables.
  • Detected While initializing a visibility attribute
  • you generate a package folder.
  • has some special sections like / * user defined includes * / to add include or require and not be overwritten.
  • To generate a String, you must specify the type "char"
  • Problem: has too much "extra code", code to detect if PHP 5, and even force the display errors of type "Notice."
  • you create an include for each file which holds the class you need. if this class was related to many other would generate a lot of code (one for each association). This code is also considered "extra" or "more" if you use the magic method __autoload, for autoloading. Or good light! the namespaces that are already in PHP 5.3
 \u0026lt;? 

php error_reporting (E_ALL);

/ ** * Model Test
PHP 5 and UML - model \\ class.Carrito.php
*
* $ Id $
*
* This file is part of Modelo Test PHP 5 y UML.
*
* Automatically generated on 16.12.2008, 00:46:11 with ArgoUML PHP module
* (last revised $Date: 2008-04-19 08:22:08 +0200 (Sat, 19 Apr 2008) $)
*
* @author Jaime M. Tan Nozawa, &lt;jtnozawa@gmail.com&gt;
* @package modelo
*/

if (0 &gt; version_compare(PHP_VERSION, '5')) {
die('This file was generated for PHP 5');
}

/* user defined includes */
// section -64--88-1-33--101592aa:11e3c5ee07c:-8000:0000000000000CB6-includes begin
// section -64--88-1-33--101592aa:11e3c5ee07c:-8000:0000000000000CB6-includes end

/* user defined constants */
// section -64--88-1-33--101592aa:11e3c5ee07c:-8000:0000000000000CB6-constants begin
// section -64--88-1-33--101592aa:11e3c5ee07c:-8000:0000000000000CB6-constants end

/**
* Short description of class modelo_Carrito
*
* @access private
* @author Jaime M. Tan Nozawa, &lt;jtnozawa@gmail.com&gt;
* @package modelo
*/
class modelo_Carrito
{
// --- ASSOCIATIONS ---


// --- ATTRIBUTES ---

/**
* Short description of attribute cantidad
*
* @access private
* @var int
*/
private $cantidad = 0;

// --- OPERATIONS ---

/**
* Short description of method __construct
*
* @access public
* @author Jaime M. Tan Nozawa, &lt;jtnozawa@gmail.com&gt;
* @return void
*/
public function __construct()
{
// section -64--88-1-33--101592aa:11e3c5ee07c:-8000:0000000000000CFA begin
// section -64--88-1-33--101592aa:11e3c5ee07c:-8000:0000000000000CFA end
}

/**
* Short description of method count
*
* @access public
* @author Jaime M. Tan Nozawa, &lt;jtnozawa@gmail.com&gt;
* @return int
*/
public function count()
{
$returnValue = (int) 0;

// section -64--88-1-33--101592aa:11e3c5ee07c:-8000:0000000000000CF4 begin
// section -64--88-1-33--101592aa:11e3c5ee07c:-8000:0000000000000CF4 end

return (int) $returnValue;
}

/**
* Short description of method guardar
*
* @access public
* @author Jaime M. Tan Nozawa, &lt;jtnozawa@gmail.com&gt;
* @return boolean
*/
public function guardar()
{
$returnValue = (bool) false;

// section -64--88-1-33--101592aa:11e3c5ee07c:-8000:0000000000000CF6
begin / / section-64 - 88-1-33 - 101592aa: 11e3c5ee07c: CF6 -8000:0000000000000

end return (bool) $ returnValue;


}} / * end of class modelo_Carrito * /

? >



2) reviewing the associations between classes
analyze several associations between classes and code generation in PHP :

Association
dependence is a terms of use, ie use class to another, who needs to be done. Is represented by a dashed arrow going from the class used to class used. The dependence shows a change in the class used may affect the operation of the kind used, but not vice versa.



ArgoUML





BoUml




>> Code generated BoUML <<
There was no change in the code with this

association >> generated code in ArgoUML <<
On line 22, before the user includes ArgoUML code generated previously, these new lines are inserted. The class used (dependent) "Shopping", takes the kind used include_once "BD." This implies that within the lifetime of an object Shopping require calling a method or an instance of BD.
 
/ ** * include modelo_BD


* * @ author Jaime M. As Nozawa, \u0026lt;jtnozawa@gmail.com>
* /
require_once ('model / class.BD.php');


Association
simple objects that collaborate can associate with each other. The difference with the unit is that it saves a reference to the other class.
This association has seaworthy this direction means that one can obtain or "see" the target object through the client object. It also means, as dependency, a method call or get the instance of a class.



ArgoUML




BoUml



>> Code generated BoUML << Bouml
To create you need to save the attribute where the reference to the class, this will be at the ends of the association. Shopping In this case an instance of BD alone, and this is stored in the new attribute "connection." Review
end of the code, note that another attribute
generated
 
\u0026lt;?

php / ** * Class
Cart
* / class Cart

{/ **
* Items in cart
* / private $ amount =
0;

&nbsp;&nbsp;/**
&nbsp;&nbsp;&nbsp;*&nbsp;Contructor
&nbsp;&nbsp;&nbsp;*/
&nbsp;&nbsp;public&nbsp;function&nbsp;__construct()
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Bouml&nbsp;preserved&nbsp;body&nbsp;begin&nbsp;0001F503

$return=NULL;

return($return);
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Bouml&nbsp;preserved&nbsp;body&nbsp;end&nbsp;0001F503
&nbsp;&nbsp;}

&nbsp;&nbsp;public&nbsp;function&nbsp;count()
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Bouml&nbsp;preserved&nbsp;body&nbsp;begin&nbsp;0001F583

$return=NULL;

return($return);
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Bouml&nbsp;preserved&nbsp;body&nbsp;end&nbsp;0001F583
&nbsp;&nbsp;}

&nbsp;&nbsp;public&nbsp;function&nbsp;guardar()

{/ / begin body preserved 0001F603 Bouml

$ return = NULL;

return ($ return);
/ / end 0001F603 Bouml preserved body


} / ** * auto_install class
DB connection association
* / private
$ link = null;}


?>

>> generated code in ArgoUML <<
not in ArgoUML creates the attribute in the class Cart, but if you create a comment about the association and the name christened to the end. I therefore manually created an attribute "connection" in the class.
EYE, only put the first part: check the line 47 and 48
 code \u0026lt;? 

php error_reporting (E_ALL);

/ ** * Model Test
PHP 5 and UML - model \\ class.Carrito.php

* * $ Id $

* * This file is part of Modelo Test PHP 5 y UML.

* * Automatically generated Wed, 16.12.2008, 1:57:32 with ArgoUML PHP module
* (last revised $ Date: 2008-04-19 8:22:08 0200 (Sat, 19 Apr 2008) $)

* * @ author James M. Nozawa So, \u0026lt;jtnozawa@gmail.com>
* @ package model
* /

if (0> version_compare (PHP_VERSION, '5 ')) {
die ("This file was generated for PHP 5') ;


} / ** *
include modelo_BD
&nbsp;*
&nbsp;*&nbsp;@author&nbsp;Jaime&nbsp;M.&nbsp;Tan&nbsp;Nozawa,&nbsp;&lt;jtnozawa@gmail.com&gt;
&nbsp;*/
require_once('modelo/class.BD.php');

/*&nbsp;user&nbsp;defined&nbsp;includes&nbsp;*/
//&nbsp;section&nbsp;-64--88-1-33--101592aa:11e3c5ee07c:-8000:0000000000000CB6-includes&nbsp;begin
//&nbsp;section&nbsp;-64--88-1-33--101592aa:11e3c5ee07c:-8000:0000000000000CB6-includes&nbsp;end

/*&nbsp;user&nbsp;defined&nbsp;constants&nbsp;*/
/ / section-64-88-1-33 - 101592aa: 11e3c5ee07c: -8000:0000000000000 CB6-
constants begin / / section-64-88-1-33 - 101592aa: 11e3c5ee07c: -8000:0000000000000 CB6-constants end

/ ** * Short description of
class modelo_Carrito

* * @ access private *
@ author James M. Tan Nozawa, \u0026lt;jtnozawa@gmail.com>
* @ package model
* / {
class
modelo_Carrito
/ / --- --- Associations
/ / generateAssociationEnd:
connection
/ / --- ATTRIBUTES ---

/ **
; * Short description of attribute number
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@access&nbsp;private
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@var&nbsp;int
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/
&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;$cantidad&nbsp;=&nbsp;0;

&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;---&nbsp;OPERATIONS&nbsp;---

Continuará... with multiplicity, aggregation / composition and generalization

0 comments:

Post a Comment