0

Methods that return boolean are usually named with 'is' prefix - isTrue(), isSet(), isNull(), etc. Is it against convention to have plurals in such names like - areTrue(), areNotNull(), etc?

Also in what cases can a method have a 'call' or 'invoke' prefix. Can I use 'call' prefix to call a DAL method from business layer, like callCreateUser()?

sotn
  • 1,833
  • 5
  • 35
  • 65
  • 2
    Java Bean convention has relied on "isTrue" or "hasTrue" since Java 1.0. You'll be contradicting that standard. – duffymo Dec 13 '16 at 19:22
  • 1
    How would you have a plural boolean? – Compass Dec 13 '16 at 19:23
  • 1
    `has` is not a valid prefix. Options are `is` or `get`. Possible duplicate: http://stackoverflow.com/questions/799280/valid-javabeans-names-for-boolean-getter-methods – Dan Armstrong Dec 13 '16 at 19:39
  • Thank you for correcting me. I didn't know. – duffymo Dec 13 '16 at 19:46
  • Regarding your second paragraph, why name something “callCreateUser” when you can name it `createUser`? The fact that it delegates to another object is an implementation detail that should not be exposed in the name. – VGR Dec 13 '16 at 19:58
  • @VGR, makes sense. When is it be appropriate to use call/invoke in the method name? Or is it never recommended. I have seen some apis with such names. Just can't find them at the moment. – sotn Dec 13 '16 at 22:29
  • I would say almost never. After all, every method is a call/invocation. – VGR Dec 14 '16 at 02:50

0 Answers0