Article 5VKWN CodeSOD: Two Addresses

CodeSOD: Two Addresses

by
Remy Porter
from The Daily WTF on (#5VKWN)

When passing data over the wire, we frequently want to aggregate that data into a data transfer object. An ideal DTO lets a client get all the data they need in a single request, without needing lots of round trips to get related objects.

Or, you could be like the contractors that Marty had to work with, and get handed this Java code:

private AddressDTO buildAddressDTO() { AddressDTO addressDTO = new AddressDTO(); addressDTO.setAddress1("add1"); addressDTO.setAddress2("add2"); addressDTO.setAddress3("add3"); addressDTO.setAddress4("add4"); addressDTO.setAddress5("add5"); addressDTO.setAddress6("add6"); addressDTO.setAddress7("add7"); addressDTO.setAddress8("add8"); addressDTO.setAddress9("add9"); addressDTO.setAddress10("add10"); addressDTO.setAddress11("add11"); addressDTO.setAddress12("add12"); addressDTO.setAddress13("add13"); addressDTO.setAddress14("add14"); addressDTO.setAddress15("add15"); addressDTO.setAddress16("add16"); addressDTO.setAddress17("add17"); addressDTO.setAddress18("add18"); addressDTO.setAddress19("add19"); addressDTO.setAddress20("add20"); return AddressDTO.builder() .address1(addressDTO.getAddress1()) .address2(addressDTO.getAddress2()) .address3(addressDTO.getAddress3()) .address4(addressDTO.getAddress4()) .address5(addressDTO.getAddress5()) .address6(addressDTO.getAddress6()) .address7(addressDTO.getAddress7()) .address8(addressDTO.getAddress8()) .address9(addressDTO.getAddress9()) .address10(addressDTO.getAddress10()) .address11(addressDTO.getAddress11()) .address12(addressDTO.getAddress12()) .address13(addressDTO.getAddress13()) .address14(addressDTO.getAddress14()) .address15(addressDTO.getAddress15()) .address16(addressDTO.getAddress16()) .address17(addressDTO.getAddress17()) .address18(addressDTO.getAddress18()) .address19(addressDTO.getAddress19()) .address20(addressDTO.getAddress20()).build();}

I assume that they realized addresses could be complicated, especially when you're working internationally, so instead of trying to resolve that complexity they just created an object with twenty string fields that could be used however a developer wanted.

Of course, the real "fun" here is that they first construct a dummy AddressDTO just by calling setters, then they create a second AddressDTO using a builder pattern. Why not do things twice, I suppose?

proget-icon.png [Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more. TheDailyWtf?d=yIl2AUoC8zA
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments