class RadarChecker:
def __init__(self) -> None:
self._issues = set()
@property
def issues(self) -> Set[str]:
return self._issues
@property
def _checkers(self) -> Iterable[Callable]:
return (
self._check_1,
self._check_2,
self._check_3,
)
def check(self) -> None:
for checker in self._checkers:
ok, issue = checker()
if not ok:
self._issues.add(issue)
The current interface of the RadarChecker
class consists of two methods: check
and issues
. The whole purpose of the check method is that it triggers computation of the issues that are returned by the issues method. So, all users of RadarChecker
call issues eventually:
checker = RadarChecker()
checker.check()
for issue in checker.issues:
# process issue
Is it possible to provide the same functionality with a simpler interface?
I'm thinking about defining the RadarIssues
class that implements the Iterable[str]
interface. We provide the same info to RadarIssues
that we do to RadarChecker
but instead of calling issues
to get the issues, the users would simply iterate over the instance of RadarIssues
. This would look roughly as follows:
radar_issues = RadarIssues()
for issue in radar_issues:
# process issue
Is it better? I will appreciate criticism and other ideas.