我当时在PHP上编写函数,而在编写函数时却使我感到困惑。描述职能职责的最佳方法是什么?
function createWallet(int $userId) {
// validate if user exists
//create wallet
}
or
**client will validate if user exists then call createWalletFunction
function createWallet(int $userId) {
//create wallet
}
答案 0 :(得分:0)
根据SOLID Principal,每个类/函数/方法应仅承担一个责任,因此我建议使用后一种方法,客户端应调用该方法以验证用户,并在成功时调用createWallet()方法。如果用户未授权,客户端也可以通知某种消息。