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();
?>
(還有更多)。
UML可能意味着很多事情。所以你想創建一個類圖並將實現轉化爲面向對象的實現?另外:你也是做UML建模或實現的唯一任務嗎? – scravy
這個Assigment是我做的一個項目(用PHP編寫的),並創建一個基本的UML模型(包含使用案例,流程圖,文檔等)。最簡單的方法是將項目的設計修改爲面向對象,使用UML工具生成類圖並開始工作,或者從模型開始一個新項目,然後執行實現。在任何情況下,我都需要使用流程圖和使用案例以及相應實施的模型。 – NotGaeL
也許你可以編輯你的問題並準確地陳述你需要什麼(順序圖,類圖,用例圖,...)下面是對UML圖各個方面的簡潔介紹:http://www.ibm.com /developerworks/rational/library/769.html – scravy