我有一个Document
类需要在保存到数据库之前进行外部授权。
可以创建一个authorize
像...这样的方法吗?
class Document:
authorize(IExternalAuthorizator authorizator):
authorization_result = authorizator.authorize(this)
// update internal state with result...
然后在用例或服务中使用它...
class UseCase:
execute(IDocumentRepository repo, IExternalAuthorizator authorizator):
doc = new Document()
doc.authorize(authorizator)
repo.save(doc)
还是我应该有这样的Document
课......
class Document:
authorize(AuthorizationResult result):
// update internal state with result...
然后用例......
class UseCase:
execute(IDocumentRepository repo, IExternalAuthorizator authorizator):
doc = new Document()
result = authorizator.authorize(doc)
doc.authorize(result)
repo.save(doc)
还是没有,只有第三种选择?
有什么帮助吗?