2 Matching Annotations
  1. Aug 2022
  2. Mar 2018
    1. Florida.voteCount and Florida.countVotes()

      There's no problem here. Florida.voteCount will actually count votes only if it needs to (say, the first time). Then, it won't count the votes again and again: it would be a flaw in the design of the class.

      On the other hand, it is this class' responsability to decide what to do when somebody needs to know the count.

      If you have Florida.voteCount and Florida.countVotes(), it means it is caller's responsability to decide when and if it must execute the actual counting or just read an already computed count.

      This logic must be inside the class, not outside. Hence I advocate for Florida.voteCount as a getter which may do the actual counting (likely only once if the status of the state (!) hasn't changed) or give the already computed count.

      A different approach would look wrong to me. (When the language hasn't the kind of syntactical sugar Eiffel has, you likely will have Florida.getVoteCount() which replace both Florida.voteCount and Florida.countVotes().