java  pattern best practice