0

When is it preferable to use getters instead of functions in Dart? In other words, when would you use getters to get something, which at the same time could be also got with a function?

  • I know that linked question ("Properties vs Methods" is regarding C# - but similar guidelines or conventions exist for other OOP languages with properties such as Swift and JavaScript, as well as COM/IDL). – Dai Jan 06 '20 at 18:23
  • @Dai Yes, thank you! –  Jan 06 '20 at 18:24

1 Answers1

0

You can read from the effective dart guide:

DO use getters for operations that conceptually access properties.

  • The operation does not take any arguments and returns a result.
  • The caller cares mostly about the result.
  • The operation does not have user-visible side effects.
  • The operation is idempotent.
  • The resulting object doesn’t expose all of the original object’s state.
Mattia
  • 5,909
  • 3
  • 26
  • 41