设计问题:哪个更好的做法? (第2部分) [英] Design Question: Which is Better practice? (part 2)
问题描述
为每个系统(A,B和C)提供3种不同的API。
我目前在后端的设计看起来像这样:
interface ProvisionData
{
public function createUser();
public function deleteUser();
public function changePassword();
}
class SystemA_API_wrapper实现ProvisionData
{
public function createUser(){...}
public function deleteUser() ...}
public function changePassword(){...}
}
class SystemB_API_wrapper实现ProvisionData
{
public function createUser(){...}
public function deleteUser(){...}
public function changePassword(){...}
}
class SystemC_API_wrapper实现ProvisionData
{
public function createUser(){...}
public function deleteUser(){...}
public function changePassword(){...}
}
系统* _API_wrapper具有不同的createUser()(和其余)功能的实现。
在前端我创建了一种代理类,它使用从Web界面收集的数据。它看起来像:
class provisionProxy
{
public $ sA = null;
public $ sB = null;
public $ sC = null; //构造函数实例化所有System * _API_wrapper对象
public function __construct (){
$ sA = new SystemA_API_wrapper();
$ sB = new SystemB_API_wrapper();
$ sC = new SystemC_API_wrapper();
}
//代理函数deleteUser调用每个
//我们的API
public function deleteUser($ username,$ password){
$ this-> sA-> deleteUser($ username,$ password);
$ this-> sB-> deleteUser($ username,$ password);
$ this-> sC-> deleteUser($ username,$ password);
}
}
有没有人有任何建议或更好的做法?
(我已经发布同样的问题,但由于技术问题,我无法登录到我的旧帐户,所以问题是修改和再次发布在我的新帐户。原始问题可以在这里找到:设计问题:哪个更好的做法? - 谢谢)
根据您不能将您的三个后端系统更改为所有访问中央系统进行用户管理(这将更好)的假设,我建议的唯一更改是为您的代理,在哪里是对三个系统中的每一个进行硬编码调用 - 最好在构造函数中创建一个ProvisionData对象列表,然后在删除/创建调用中循环遍历该列表并调用相应的我这个意思是说,如果将来某个时候你必须添加系统D,那么可以用一个更改来实现这一点。单一的地方。
(我的PHP技能有点麻烦,所以不会尝试提供代码)。
I've got a web interface from which I will gather user data (username,pass,email,etc..) and the backend has to provision these data into 3 other systems (SystemA, SystemB, SystemC).
The provisioning is being done by 3 different APIs one for each system (A,B and C).
My current design in the backend looks something like this:
interface ProvisionData
{
public function createUser();
public function deleteUser();
public function changePassword();
}
class SystemA_API_wrapper implements ProvisionData
{
public function createUser(){ ... }
public function deleteUser(){ ... }
public function changePassword(){ ... }
}
class SystemB_API_wrapper implements ProvisionData
{
public function createUser(){ ... }
public function deleteUser(){ ... }
public function changePassword(){ ... }
}
class SystemC_API_wrapper implements ProvisionData
{
public function createUser(){ ... }
public function deleteUser(){ ... }
public function changePassword(){ ... }
}
Each of the System*_API_wrapper has different implementation of createUser() (and the rest) functions.
In the frontend I've created a kind of proxy class which I feed with the data gathered from the web interface.. It looks like:
class provisionProxy
{
public $sA = null;
public $sB = null;
public $sC = null;//constructor instantiates all System*_API_wrapper objects
public function __construct() {
$sA = new SystemA_API_wrapper();
$sB = new SystemB_API_wrapper();
$sC = new SystemC_API_wrapper();
}
// proxy function deleteUser calls deleteUser() of each of
// our APIs
public function deleteUser($username, $password) {
$this->sA->deleteUser($username, $password);
$this->sB->deleteUser($username, $password);
$this->sC->deleteUser($username, $password);
}
}
Does anyone have any suggestion or a better practice?
(I've already posted the same question but due to technical problems I can't login to my old account, so the question is revised and posted again under my new account. Original question can be found here: Design Question: Which is Better practice? - thanks)
Based on the assumption that you can't change your three backend systems to all access a central system for user management (which would be better), the only change I would suggest is for your proxy, where you are hard coding calls to each of your three systems - it would be better to create a list of ProvisionData objects in your constructor and then in your delete/create calls, loop through that list and call the appropriate method on each.
This means that if, at some point in the future, you have to add system D to this, then that can be done with a change in a single place.
(My PHP skills are a bit ropy, so won't attempt to provide the code).
这篇关于设计问题:哪个更好的做法? (第2部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!