Download Growing Better Software

Transcript
46
Growing Better Software
3.2 Beware of N instead of many
All diagrams in the world won’t prevent us from solving problems
for a fixed number of entities, rather than for ’many’ of them.
This is a common mistake, which we should be aware of when
designing a system.
This mistake manifests itself in data structures that have several
fields or properties that represent essentially the same type of
information, for instance:
class person
{
date birthdate;
string name;
person child1;
person child2;
person child3; /* fixed maximum of 3
children */
}
We can’t iterate these properties with a loop4; this means we will
need to write several pieces of code, one to deal with each
property. Changes in one piece of code imply the others need to
be updated as well. In other words, solving a problem for a fixed
number of entities rather than 1 or many will increase
maintenance. It also creates an unnecessary logical limitation in
our system.
4 Some object­oriented languages provide a workaround by allowing access
to Run­Time Type Information. This will however disallow us to find
certain problems as early as in compile time.