K(n) - Why design patterns exist

In mathematics K(n) is the complete graph sequence, a function that returns the number of lines between a discreet set of equidistant points.

The first five of the sequence are

K(1) = 0
K(2) = 1
K(3) = 3
K(4) = 5
K(5) = 15

K(100) = 1050

Now, imagine if you will each point represents a class in a program. Each line represents a line of communication between classes. As can be seen, without a design paradigm of some form things rapidly spiral out of control where, at the highest scale changing one class can involve hundreds of interactions.

Design patterns, regardless of which one they are, combat this problem by severing lines of communication between classes. If two classes can’t talk to each other their interaction does not need to be tested because it doesn’t exist. Scope operators help combat this problem as well on the method level - a private method need only be tested for its interactions within the class that has it, a protected one within the family of classes.

One thing the complete graph should visually lay bare is the importance of keeping public methods minimal, API’s consistent and so on. A lot of what we do in large applications (cough ::dependency injection:: cough) is ultimately aimed at taming this monster.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.