N
Nunaya
We have developed two objects called "customer" and "salesrep". For
simplicity, assume that these two objects will talk directly to a
database. The database has three tables: customers, customersalesreps
(allows multiple salesreps to be associated with a customer), and
salesreps. The customer object has business rules that allow
manipulation of customer information (add,update,delete,select,etc).
The salesrep object has business rules that allow manipulation of
salesrep information (add,update,delete,select,etc).
Question 1: Where is the proper place to put a method called
"AddCustomerSalesrep" that adds a new salesrep to the
customersalesreps table with the customerid and salesrepid? Is it in
the customer or salesrep object? (Or is it in a third object we
should create called "customersalesrep"?)
Question 2: Assume one of the business rules desired is to validate
the salesrepid prior to adding a new salesrep to a customer. Also
assume that the salesrep object already has a method called
"issalesrepvalid" which takes a salesrepid and makes sure it exists in
the salesreps table. If we put AddCustomerSalesrep in the customer
object, would we want to validate the salesrepid by having the
customer object instantiate the salesrep object and call the method
called "issalesrepvalid"? Does this break the principle of
encapsulation or is there a better way to design this?
Thanks in advance for any insight.
simplicity, assume that these two objects will talk directly to a
database. The database has three tables: customers, customersalesreps
(allows multiple salesreps to be associated with a customer), and
salesreps. The customer object has business rules that allow
manipulation of customer information (add,update,delete,select,etc).
The salesrep object has business rules that allow manipulation of
salesrep information (add,update,delete,select,etc).
Question 1: Where is the proper place to put a method called
"AddCustomerSalesrep" that adds a new salesrep to the
customersalesreps table with the customerid and salesrepid? Is it in
the customer or salesrep object? (Or is it in a third object we
should create called "customersalesrep"?)
Question 2: Assume one of the business rules desired is to validate
the salesrepid prior to adding a new salesrep to a customer. Also
assume that the salesrep object already has a method called
"issalesrepvalid" which takes a salesrepid and makes sure it exists in
the salesreps table. If we put AddCustomerSalesrep in the customer
object, would we want to validate the salesrepid by having the
customer object instantiate the salesrep object and call the method
called "issalesrepvalid"? Does this break the principle of
encapsulation or is there a better way to design this?
Thanks in advance for any insight.