我正在设计一个API,希望它易于使用。因此,如果我有客户、账单和付款。这样做有意义吗:客户、客户处理程序、账单、账单处理程序、付款和付款处理程序等对象吗?这样,当开发人员想要处理客户时,他/她知道要创建一个客户处理程序,然后所有可能想要执行的与客户有关的功能都在处理程序中。
方法,例如:
客户处理员
- AddCustomer(customer)
- GetCustomer(customerID)
- GetCustomerCount()
声明处理程序:
- AddStatement(customerID)
- GetStatement(statementID)
- GetStatementCount(customerID)
付款处理程序:
- GetPaymentsByCustomer(customerID)
- GetPayment(paymentID)
- GetPaymentCountByCustomer(customerID)
This way if the developer wants to work on receiving payments he/she knows to go to the PaymentHandler. My coworker thought that functions like GetPayments(customerID) belong in a class that manages the customer. So, it would be like Customer.GetPayments() AS Payments. But if I have some other entity like Worker, there would be Worker.GetPayments() AS Payments. So, I see the logic with both approaches. The first one groups things together so that if no matter whom the payment is coming from you get it all from one class by having functions like GetPaymentsByCustomer(CustomerID) and GetPaymentsByWorker(WorkerID). This way one does not have to stumble through different handler or manager objects to get payments. Both approaches make sense to me, how about you? Or, are we both off and there is a better way to do this? Thanks in advance!