Let’s say we have an object that handles instances of
Person. For example
PeopleScreen renders instances of
Person so this should be the only format we provide to it. Let me explain.
There is a new flow that ends in opening
PeopleScreen but all the information for the list of people are in a
Map<String, String>. There is no reason to alter
PeopleScreen in order to support this new format:
Why we shouldn’t do it
We could argue that by doing so we tie the object with each special format making the code hard to maintain and scale but the real reason is that we violate the SRP principle since
PeopleScreen will have more than one reasons to change. One if something changes in the way we render and two if something changes in
What we should do
We should keep
PeopleScreen only consuming
Person and move all transformations to their own objects allowing a coordinator to transform and pass data around.