Skip to content

Files

Latest commit

 

History

History
35 lines (26 loc) · 813 Bytes

avoid_classes_with_only_static_members.md

File metadata and controls

35 lines (26 loc) · 813 Bytes

Pattern: Use of class with only static members

Issue: -

Description

Creating classes with the sole purpose of providing utility or otherwise static methods is discouraged. Dart allows functions to exist outside of classes for this very reason.

Example of incorrect code:

class DateUtils {
 static DateTime mostRecent(List<DateTime> dates) {
  return dates.reduce((a, b) => a.isAfter(b) ? a : b);
 }
}

class _Favorites {
 static const mammal = 'weasel';
}

Example of correct code:

DateTime mostRecent(List<DateTime> dates) {
 return dates.reduce((a, b) => a.isAfter(b) ? a : b);
}

const _favoriteMammal = 'weasel';

Further Reading