Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One problem with using chained references, such as <code>order.user.address.city</code>, is that higher-order dependencies get "baked into" the structure of code outside the class.</p> <p>Ideally, in cases when you refactor your class, your "forced changes" should be limited to the methods of the class being refactored. When you have multiple chained references in the client code, refactoring drives you to make changes in other places of your code.</p> <p>Consider an example: suppose that you'd like to replace <code>User</code> with an <code>OrderPlacingParty</code>, an abstraction encapsulating users, companies, and electronic agents that can place an order. This refactoring immediately presents multiple problems:</p> <ul> <li>The <code>User</code> property will be called something else, and it will have a different type</li> <li>The new property may not have an <code>address</code> that has <code>city</code> in cases when the order is placed by an electronic agent</li> <li>The human <code>User</code> associated with the order (suppose that your system needs one for legal reasons) may be related to the order indirectly, - for example, by being a designated go-to person in the definition of the <code>OrderPlacingParty</code>.</li> </ul> <p>A solution to these problems would be to pass the order presentation logic everything that it needs directly, rather than having it "understand" the structure of the objects passed in. This way you would be able to localize the changes to the code being refactored, without spreading the changes to other code that is potentially stable.</p> <pre><code>interface OrderPresenter { void present(Order order, User user, Address address); } interface Address { ... } class PhysicalAddress implements Address { public String getStreetNumber(); public String getCity(); public String getState(); public String getCountry(); } class ElectronicAddress implements Address { public URL getUrl(); } interface OrderPlacingParty { Address getAddress(); } interface Order { OrderPlacingParty getParty(); } class User implements OrderPlacingParty { } class Company implements OrderPlacingParty { public User getResponsibleUser(); } class ElectronicAgent implements OrderPlacingParty { public User getResponsibleUser(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload