locked
Stamp Coupling Vs Data Coupling Vs Mixed RRS feed

  • Question

  • User1820827484 posted

    Hello Community,

    I would like to have advice on which Stamp or Data Coupling in scenario:

    - Saving customer information by passing Customer Object to Save method.  (Stamp Coupling)
    - Saving customer information by passing large number of customer fields as arguments to Save method (Data Coupling)
    -  Mixed approach in design, because in some scenarios only one argument is enough for function but in save/update scenario need all of fields regardless of empty or filled at save time.

    Although these both types (stamp,data) both fall in low coupling category.  Which one is good one to following OR mixed one is fine ?

    Wednesday, September 10, 2014 4:45 PM

Answers

  • User-760709272 posted

    For something like a get where you only pass one param like an ID that is fine to do it using "1" as no matter how the customer object changes, you won't need to update your method signature.  For updates I would also just pass the Customer object with the id on it populated so that the update code knows the id of the customer and all the fields.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 11, 2014 3:32 AM

All replies

  • User-760709272 posted

    The first one every time.

    Wednesday, September 10, 2014 4:57 PM
  • User1820827484 posted

    Thank you Aidy,

    But first one recommended  for only for Save scenario. What's about if order details need be generated by customer id. The getOrderDetails method should be like 1 or 2?

    1. getOrderDetails(int customerId); // data coupling

    2. getOrderDetails(Customer customer); // Get the customer_id from Customer Object  (stamp coupling)

    Wednesday, September 10, 2014 6:09 PM
  • User-760709272 posted

    For something like a get where you only pass one param like an ID that is fine to do it using "1" as no matter how the customer object changes, you won't need to update your method signature.  For updates I would also just pass the Customer object with the id on it populated so that the update code knows the id of the customer and all the fields.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 11, 2014 3:32 AM