java - Is there any best practice about how to organize methods? -


this might of theoretical question, let me try explain example:

  • i have pojo cow , pojo calving
  • every cow has list of calvings

there check in code every calving needs @ least 7 month window, means that, if new calving added

  • there has validation calving before newly added one, @ least 7 months before newly added 1 and;
  • in case there calving after newly added one, has @ least 7 months after newly added one.

now, wonder best practice put method validate newly added calving. have 2 possible solutions:

option 1:

i make following methods in cow class:

  • private calving getpreviouscalving(date calvingdate)
  • private calving getnextcalving(date calvingdate)
  • public boolean iscalvingin7monthwindow(date datetocheck)

option 2:

i make following methods in cow class:

  • public calving getpreviouscalving(date calvingdate)
  • public calving getnextcalving(date calvingdate)

and 1 in calving class:

  • public boolean isin7monthwindow(calving calvingbefore, calving calvingafter, date datetocheck)

the reason i'm in doubt isin7monthwindow method gives information potential new calving (option 2), not cow, logical should in calving class no? however, option 1 cleaner , has easier access necessary data check (as cow has calving list).

i hope isn't broad , not opinion based. thoughts?


Comments