Page 1 of 1

UML TO PHP CLASS

Posted: Thu Nov 02, 2006 9:19 am
by kpraman
How to create class from uml,

i have uml like this,

MemberTypes

-MemberTypeId
-MemberTypeName
-MemberTypeDesc

+AddMemberType()
+DeleteMemberType()

How to write class file for above.

Thanks

Posted: Thu Nov 02, 2006 9:38 am
by malcolmboston
a class file?

what do you want to do with the data? parse it? store it?

we need more info!

Re: UML TO PHP CLASS

Posted: Thu Nov 02, 2006 9:45 am
by jmut
kpraman wrote:How to create class from uml,

i have uml like this,

MemberTypes

-MemberTypeId
-MemberTypeName
-MemberTypeDesc

+AddMemberType()
+DeleteMemberType()

How to write class file for above.

Thanks
Usually the editor you use to create the UML should have this feature (to export to PHP,JAVA etc).
I'm trying to find such a tool as well...but for php it is quite hard....java is more strict...and easier to implement such tool I guess.
+ this will only be possible for php5 ..thats for sure.

Posted: Thu Nov 02, 2006 9:48 am
by Weirdan
+ this will only be possible for php5 ..thats for sure.
What would prevent you from outputting valid php4 code? If SimpleTest can do that (generate mocks), any application can do that as well.

Posted: Thu Nov 02, 2006 11:46 am
by wwwapu
Umbrello can do it. It has some weak points, but it's free, which is a big plus.

Code: Select all

/**
 * class MemberTypes
 */
class MemberTypes
{

  /** Aggregations: */

  /** Compositions: */

   /*** Attributes: ***/

  /**
   * @access private
   */
  private $MemberTypeId;

  /**
   * @access private
   */
  private $MemberTypeName;

  /**
   * @access private
   */
  private $MemberTypeDesc;


  /**
   *
   * @return 
   * @access public
   */
  public function addMemberType( ) {
    
  } // end of member function addMemberType

  /**
   *
   * @return 
   * @access public
   */
  public function deleteMemberType( ) {
    
  } // end of member function deleteMemberType





} // end of MemberTypes
?>

Posted: Thu Nov 02, 2006 7:40 pm
by kpraman
i want to pass values of $MemberTypeId,$MemberTypeName,$MemberTypeDesc and in the method,

public function addMemberType(), i want to insert into database. "INSERT INTO tblname SET membertypename='$MemberTypeName, membertypedesc='$MemberTypeDesc'".

similarly for deleteMemberType( ), "DELETE FROM tblname WHERE membertypeid='$MemberTypeId'";

Posted: Fri Nov 03, 2006 1:40 am
by jmut
Weirdan wrote:
+ this will only be possible for php5 ..thats for sure.
What would prevent you from outputting valid php4 code? If SimpleTest can do that (generate mocks), any application can do that as well.
Well, I did not point it out correctly. This will only make sense for php5...in my opinion. php4 just lacks so many OOP features that UMLing the classes is kind of pointless. Just php4 sux in OOP thats all, and UML is to express OOP approach.

Posted: Fri Nov 03, 2006 1:50 am
by kpraman
i wrote the code like this,

Code: Select all

<?php
class MemberTypes{


      public function addMemberType($MemberTypeName, $MemberTypeDesc, $tblname) { 
  
        $query=mysql_query("INSERT INTO $tblname SET membertypename='$MemberTypeName', membertypedesc='$MemberTypeDesc'");
    
  }          


}


$newCls= new MemberTypes();

$newCls->addMemberType('Admin', 'Assigns membership', $tblname);

?>
This works fine. Since in the UML the variablname, $MemberTypeName, $MemberTypeDesc are marked a private (-), how to implement it?

Posted: Fri Nov 03, 2006 2:00 am
by theFool
ever heard of "poseidon" for uml generation.

only used it for java coe generation but it seems to have an old plugin for php4 code generation. but haven't investigate further.
try it and tell us what u've got :)

http://www.gentleware.com/73.html

Posted: Fri Nov 03, 2006 3:03 am
by Chris Corbyn
kpraman wrote:i wrote the code like this,

Code: Select all

<?php
class MemberTypes{


      public function addMemberType($MemberTypeName, $MemberTypeDesc, $tblname) { 
  
        $query=mysql_query("INSERT INTO $tblname SET membertypename='$MemberTypeName', membertypedesc='$MemberTypeDesc'");
    
  }          


}


$newCls= new MemberTypes();

$newCls->addMemberType('Admin', 'Assigns membership', $tblname);

?>
This works fine. Since in the UML the variablname, $MemberTypeName, $MemberTypeDesc are marked a private (-), how to implement it?
I think you're missing the point. Before you start playing with UML I'd probably try to understand OOP syntax first. $MemberTypeName, $MemberTypeDesc are properties, not function parameters or local variables (i.e. you access them with $this->.... ). The fact that they are private won't affect using them from inside the class, and if you need to adjust the values from outside just create public setMemberTypeName($value), setMemberTypeDesc($value) methods which can do it for you.