Fragility of Design-Pattern Named Classes

Design patterns are about how something does it’s job, rather than why. Using a design pattern name in the name of a class makes it quite fragile. For example, if you have called all your classes BlahBlahState, then refactoring to a Strategy is quite invasive, but if it’s phrased in terms of the why, then the names don’t need to change.

A good analogy here is the relation of unit tests to implementation; you should be able to change the internal implementation of the class without changing the tests. If you can’t, then the tests are too brittle. Likewise, you should be able to change the implementation without changing the class name; if your class name is tied to the implementation, through the pattern name, then it’s too brittle.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>