Not*_*aeL 2 oop uml modeling procedural-programming
我有一个小的PHP项目(大约3000行),我需要制作它的BASIC UML模型,从使用图,序列图和状态图的情况开始,可能是类图,并可能用协作图扩展它.
我是UML建模的新手,这是我第一次将模型从实现中取出而不是相反(不是非常有用,除非你进入逆向工程,但无论如何,这是一个分配)
现在,我应该如何处理这个问题?如果我的项目有OO实现,一些UML工具可以让我的生活变得非常简单,但事实并非如此,所以我想知道我是否应该将我的项目重写为OO以及如何做(我的意思是,是否有一些标准的基础我应遵循的指导方针或程序?),或者我是否应该按原样制作项目模型(在这种情况下,哪种建模工具最好).
我的项目也是在Eclipse IDE上编写的,有人知道它的任何插件来帮助我完成这个UML建模任务吗?
停
您之前是否使用面向对象编程?
你使用过OO建模技术吗?
您是否在为PHP文件使用名称空间或函数前缀("("mylib.php","function mylib_dosomething(){...}")")?
不要快速跳转到UML.UML是为了制作一份文件,记录下你的想法.
您必须先考虑一下,您将如何处理网站,然后记录和建模您的新网站的工作方式.
UML是一个很棒的工具,但是,如果你脑海中的设计很乱,那么你的文档就会搞得一团糟.
你有一个工作网站,并想要替换它.主要有两种方法.
(1)从Scratch开始:
如果您有使用OO的经验,并且您可以忘记您的旧网站,请保持其工作,并使用OO或其他一些现有框架从"临时"开始新的网站.
(2)重构
或者,您希望维护当前的网站,并逐步迁移到OO.?它也被称为"重构".
您可以从认为主程序或主要php文件是一个大对象(程序)文件开始,每个库文件也是对象.
例:
让我们说你有几个php文件.某些文件是页面的主文件.包含一些文件,甚至在页面文件中重复.其他的,只是具有功能的"库"文件.
<?php
// "indexfuncs1.php"
// this is an auxiliary file for "index.php",
// and has some free procedural code.
echo "indexfuncs1.php: dosomething()";
?>
Run Code Online (Sandbox Code Playgroud)
<?php
// "funcslib.php"
// this is an library file,
// and has only functions and constants,
define ("ANYCONST", "Hello World");
function HelloWorld()
{
echo ANYCONST;
}
?>
Run Code Online (Sandbox Code Playgroud)
<?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");
?>
Run Code Online (Sandbox Code Playgroud)
并开始将它们变成这样:
<?php
// "indexfuncs1.php"
// this is an auxiliary file for "index.php",
// and has some free procedural code.
function indexfuncs1_dosomething()
{
echo "indexfuncs1.php: dosomething()";
}
?>
Run Code Online (Sandbox Code Playgroud)
<?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;
}
?>
Run Code Online (Sandbox Code Playgroud)
<?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();
}
?>
Run Code Online (Sandbox Code Playgroud)
而且还没有OO.因为,它是一个中间步骤.
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();
?>
Run Code Online (Sandbox Code Playgroud)
(更多内容).