A team is reviewing the design of a shop's point-of-sale system, which has a checkout window, a RegisterController, a Sale class holding line items, and a database. Which of the following statements about how responsibilities should be assigned are sound? Select all that apply.
If Sale calls methods on LineItem three times, those calls add three to the fan-out of Sale.
Although Sale holds the data to be saved, giving persistence to a separate SaleRepository can keep Sale more cohesive.
The checkout window should update Sale directly, since it is the object that receives the button click first.
Low Coupling means the best design is one in which no class depends on any other class.
RegisterController should receive the end-sale event and delegate the total calculation to Sale rather than computing it.
Unlock full course notes by signing up
Classify the responsibilities of ticketing objects
A ticketing application assigns several kinds of responsibility to its objects. Match each category to the example that best illustrates it. Classify the behaviour explicitly described, rather than additional work the object might perform internally.
Choose who creates a cart line
An online shop uses four classes with the following roles:
Cart owns the collection of CartLine objects and receives the product identifier, quantity and unit price when an item is added.
CartLine stores those three values for one item.
Count the maintenance impact of responsibility allocation
A parcel application has five checkout classes. Compare these two allocations of delivery-fee responsibility:
Original allocation: Each checkout class has its own quoteDelivery method. Each of these five method bodies independently contains the fee rules for Local, Regional and Express delivery. There are no shared fee helpers.
Revised allocation: Each checkout's quoteDelivery method passes the customer's chosen mode name to one shared DeliverySelector.create method, then asks the returned delivery object for its fee through the same operation. DeliverySelector.create holds an explicit mapping from each supported mode name to its delivery class, and currently maps Local, Regional and Express to LocalDelivery, RegionalDelivery and ExpressDelivery. Each of these classes implements exactly one fee method, and that method depends only on its own mode's rule. Every checkout already uses the selector, and quoteDelivery passes any mode name through without checkout-specific validation.
Dependencies after an Information Expert refactor
A payroll design has five classes. Department holds a list of its Employee objects, and each Employee holds a reference to its PayGrade. In the original design, PayrollReport gets the employees from Department, reads each employee's name, hours and grade, asks PayGrade for the hourly rate, asks TaxTable for the tax rate, computes net pay and prints a line per employee.
The team refactors using Information Expert. Employee.netPay() now computes net pay using its own hours, its PayGrade and a tax rate it requests from TaxTable. Department.totalNetPay() sums its employees' net pay. PayrollReport gets the employees from Department, prints each employee's getName() and netPay(), then prints Department.totalNetPay().
Treat a dependency as directed (class X depends on class Y) and count each ordered pair of classes once, however many calls it involves. How many distinct dependencies does the refactored design contain? Answer as a whole number.