UML TO PHP CLASS

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

UML TO PHP CLASS

Post 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
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

a class file?

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

we need more info!
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: UML TO PHP CLASS

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post 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
?>
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post 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'";
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post 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.
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post 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?
User avatar
theFool
Forum Newbie
Posts: 17
Joined: Thu Oct 26, 2006 2:00 am
Location: Berlin, DE

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
Post Reply