Performance: DTO pattern for data transfer
MEDIUM IMPACT
This pattern affects the amount of data sent over the network and the processing time on both client and server during data transfer.
public class UserDTO { private String username; private String email; // getters and setters } @GetMapping("/users/{id}") public UserDTO getUser(@PathVariable Long id) { User user = userRepository.findById(id).orElse(null); if (user == null) return null; UserDTO dto = new UserDTO(); dto.setUsername(user.getUsername()); dto.setEmail(user.getEmail()); return dto; }
public class User { private Long id; private String username; private String password; private String email; private Date createdAt; // getters and setters } @GetMapping("/users/{id}") public User getUser(@PathVariable Long id) { return userRepository.findById(id).orElse(null); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Sending full entity as JSON | N/A | N/A | High due to large JSON parsing | [X] Bad |
| Sending DTO with minimal fields | N/A | N/A | Low due to smaller JSON parsing | [OK] Good |