有些人可能知道下面的源代码来自哪里(尽管它得到了简化)。问题是,安全范围常量何时在OOP中变得“值得”。
class Authenticate
{
// The permissions to request.
private static $CLASS_SCOPES = [
Service1:Permission1; <-- valuable here? I think not.
Service1:Permission2; <-- valuable here? maybe, but I think not.
Service1:Permission3; <-- valuable here?
Service1:Permission4; <-- valuable here? etc...
];
public function run($pathToJsonFile, $email = null)
{
// Create an authenticated client object.
$client = $this->createAuthenticatedClient($pathToJsonFile, $email);
// Create a service object.
$service = new Service($client);
$this->non-existent_function_do_something($service);
}
private function createAuthenticatedClient($pathToJsonFile, $email)
{
$client = new Client();
$client->setApplicationName('service sample');
$client->setScopes(self::$CLASS_SCOPES);
// Load the service account credentials.
$client->setAuthConfig($pathToJsonFile);
return $client;
}
}
我知道许多用户首先想到的是“此问题过于广泛”或“超出本网站的范围”。但是我认为这些是没有尝试抽象好的OOP设计逻辑的借口。截止点落在哪里?我试图提出一个非常具体的问题,概述(或开始)什么时候值得采用程序的一部分代码并将其封装的一般指南。