私は本当に大きなスクリプトを持っています。データベース クラス、基本クラス、ユーザー認証クラス、リセラー認証クラス、ペイパル IPN クラス、ダウンロード クラス、およびプラグイン クラスがあります。
Base クラスは、データベース クラスを次のように拡張します。
class Base extends database
{
var $userid;
var $root;
var $config
function Base($username, $password, $host, $database)
{
// Init DB
$this -> database($hostname, $database, $username, $password);
$this -> config = $this -> fetch(...);
// and the code goes on
}
function anyFunction()
{
$this -> Downloads -> dloadFunction();
}
}
class users extends Base
{
var $userData;
function users()
{
// initialize user, check if he is logged in, if he has cookies, load the user vars in $this -> userData
}
function userFunction1()
{
$this -> anyFunction();
}
}
class resellers extends Base
{
var $resellerData;
function resellers()
{
// initialize resellers, check if he is logged in, if he has cookies, load the user vars in $this -> resellerData
}
}
class IPN extends Base
{
}
class Downloads extends Base
{
function dloadFunction()
{
}
}
class Plugins extends Downloads
{
}
?>
そして、私は自分のコードを次のように呼び出します:
<?php
$Base = new Base($user, $pass, $host, $db);
$user = new user();
$Base -> user = $user;
$reseller = new reseller();
$Base -> reseller = $reseller;
$downloads = new Downloads();
$downloads -> Plugins = new Plugins();
$Base -> Downloads = $downloads;
$Base -> users -> updateEmail();
// and the code goes on..
?>
構造がかなり悪いと思います。それが、シングルトンメソッドを実装したい理由です。どうすればこれを達成できますか?
助けてください。