2011-12-03 112 views
2

我有一個小型的PHP項目(大約3000行),我需要爲它創建一個BASIC UML模型,從使用圖,序列圖和狀態圖的案例開始類圖,也可以用協作圖來擴展它。如何將Procedural項目移植到面向對象項目中

我是UML建模新手,這是我第一次將模型從實現中取出,而不是相反(除非您進入逆向工程,否則不是很有用),但這是一個分配)

現在,我該如何解決這個問題?如果我的項目具有面向對象的實現,一些UML工具可以使我的生活變得非常容易,但事實並非如此,所以我想知道我是否應該將項目重寫爲面向對象以及如何去做(我的意思是,是否有一些標準的基礎指導方針或程序,我應該遵循?),或者如果我只是把項目的模型變成現實(在那種情況下,哪個建模工具最好)。

另外我的項目是在Eclipse IDE上編寫的,有人知道它的任何插件可以幫助我完成這個UML建模任務嗎?

+1

UML可能意味着很多事情。所以你想創建一個類圖並將實現轉化爲面向對象的實現?另外:你也是做UML建模或實現的唯一任務嗎? – scravy

+0

這個Assigment是我做的一個項目(用PHP編寫的),並創建一個基本的UML模型(包含使用案例,流程圖,文檔等)。最簡單的方法是將項目的設計修改爲面向對象,使用UML工具生成類圖並開始工作,或者從模型開始一個新項目,然後執行實現。在任何情況下,我都需要使用流程圖和使用案例以及相應實施的模型。 – NotGaeL

+1

也許你可以編輯你的問題並準確地陳述你需要什麼(順序圖,類圖,用例圖,...)下面是對UML圖各個方面的簡潔介紹:http://www.ibm.com /developerworks/rational/library/769.html – scravy

回答

5

STOP

你有面向對象編程之前工作?

您是否使用過O.O.建模技術?

您是否使用PHP文件的名稱空間或函數前綴(「(」mylib.php「,」function mylib_dosomething(){...}「)」)?

請不要跳到U.M.L.,這麼快。 U.M.L.就是要製作一份文件, 什麼是你的腦海。

您必須首先考慮,您將如何處理網站, 及更高版本,文檔和模型您的新網站將如何工作。

U.M.L.是一個很棒的工具,但是,如果你腦子裏的設計亂七八糟,那麼你的文檔就會混亂不堪。

您有一個工作網站,並且想要替換它。 有兩種主要的方法。

(1)從頭開始:

如果你有經驗的OO,你可以對你的舊網站忘了,離開它的工作, 和「從零開始」開始一個新的網站使用OO或者一些現有的框架。

(2)重構

或者,你想保持目前的網站,並遷移到O.O., 一步一步來。 ?它也被稱爲「重構」。

您可能首先想到您的主程序或主php文件是一個大對象(程序)文件,並且每個庫文件也都是對象。

例子:

讓suppouse你有幾個PHP文件。有些文件是頁面的主要文件。包含一些文件,甚至在頁面文件中重複。其他人,只有功能的「圖書館」文件。


<?php 
// "indexfuncs1.php" 

// this is an auxiliary file for "index.php", 
// and has some free procedural code. 

echo "indexfuncs1.php: dosomething()"; 

?> 

<?php 
// "funcslib.php" 

// this is an library file, 
// and has only functions and constants, 

define ("ANYCONST", "Hello World"); 

function HelloWorld() 
{ 
    echo ANYCONST; 
} 

?> 

<?php 
// "index.php" 

// only declarations, doesn't do anything, by itself 
//include("funcslib.php"); 
//require("funcslib.php"); 
//require_once("funcslib.php"); 
include_once("funcslib.php"); 

// this code is in other file, and its executed 
include("indexfuncs1.php"); 

echo "index.php: Hello World"; 
HelloWorld(); 

// this code is in other file, and its executed 
include("indexfuncs1.php"); 

?> 

,並開始把它們變成這樣:

<?php 
// "indexfuncs1.php" 

// this is an auxiliary file for "index.php", 
// and has some free procedural code. 

function indexfuncs1_dosomething() 
{ 
    echo "indexfuncs1.php: dosomething()"; 
} 

?> 

<?php 
// "funcslib.php" 

// this is an library file, 
// and has only functions and constants, 

define ("funcslib_ANYCONST", "Hello World"); 

function funcslib_HelloWorld() 
{ 
    echo funcslib_ANYCONST; 
} 

?> 

<?php 
// "index.php" 

// only declarations, doesn't do anything, by itself 
//include("funcslib.php"); 
//require("funcslib.php"); 
//require_once("funcslib.php"); 
include_once("funcslib.php"); 

function index_main() 
{ 
    // this code is in other file, and its executed 
    indexfuncs1_dosomething(); 

    echo "index.php: Hello World"; 

    funcslib_HelloWorld(); 

    // this code is in other file, and its executed 
    indexfuncs1_dosomething();  
} 

?> 

而且沒有O.O.,但。因爲它是一箇中間步驟。

Lets start by transform each web page into a single class, without inheritance, without parent classes. 

<?php 
// "indexfuncs1.php" 

// this is an auxiliary file for "index.php", 
// and the free procedural code have become a class. 

class indexfuncs1 { 
    function dosomething() 
    { 
     echo "indexfuncs1.php: dosomething()";  
    } // function dosomething() 
} // class IndexPage  

?> 


<?php 
// "index.php" 

// only declarations, doesn't do anything, by itself 
//include("funcslib.php"); 
//require("funcslib.php"); 
//require_once("funcslib.php"); 
include_once("funcslib.php"); 

class IndexPage { 
    function main() 
    { 
     $myAux = new indexfuncs1(); 

     // this code is in other file, and its executed 
     $myAux->dosomething(); 

     echo "index.php: Hello World"; 

     funcslib_HelloWorld(); 

     // this code is in other file, and its executed 
     $myAux->dosomething(); 
    } // function main() 
} // class IndexPage 

function index_main() 
{ 
    $myPage = new IndexPage(); 
    $myPage->main(); 
} // function index_main(...) 

// --> the only allowed global procedural code: 
index_main(); 

?> 

(還有更多)。

+0

好吧,現在中間步驟就是我所在的位置:我的文件都不包含除函數或常量定義以外的任何內容,而是通過調用這些函數(.phtml文件)來生成網頁的文件主要是HTML內容,因爲網站不是那麼動態,結構上說) – NotGaeL

+0

順便說一句:非常好的答案,我幾乎接受它,但它錯過了一些東西:現在你知道我在哪裏,我應該做移植嗎? (此外,該網站甚至不在線,這只是我在Uni的一個主題項目) – NotGaeL

+0

@elcodedocle:您可能需要刷新頁面。我爲每個代碼添加了一個類。它沒有完成。您可能想繼續,因爲它可能會幫助您爲將來的類似(工作)項目... – umlcat