I just found myself creating a class called "InstructionBuilderFactoryMapFactory". That's 4 "pattern suffixes" on one class. It immediately reminded me of this:
http://www.jroller.com/landers/entry/the_design_pattern_facade_pattern
Is this a design smell? Should I impose a limit on this number?
I know some programmers have similar rules for other things (e.g. no more than N levels of pointer indirection in C.)
All the classes seem necessary to me. I have a (fixed) map from strings to factories - something I do all the time. The list is getting long and I want to move it out of the constructor of the class that uses the builders (that are created by the factories that are obtained from the map...) And as usual I'm avoiding Singletons.
Before we dive into learning about some of the most common types of code smells, let’s first answer the important question: What are Code Smells? Code smells are common programming characteristics that might indicate a problem in the code. Many times, the problem may be clear and visible.
Many times, these code smells are a result of novice programmers who fail to identify when and where to put their design patterns to good use. 12. Switch Statements If you’ve been a developer for any amount of time I’m sure you’ve heard (hopefully) that switch statements are often preferred over if-else statements.
Plus, this one is similar to Switch Statements anyways, and per the Bad Code Smells Taxonomy, it should be part of The Object-Orientation Abusers. Regardless of what category we put this code smell in, I know we’re all familiar with this one.
Here are some common Coupler Code Smells: 1 Inappropriate Intimacy 2 Indecent Exposure 3 Feature Envy 4 Message Chains 5 Middle Man More ...
A good tip is: Your class public API (and that includes it's name) should reveal intention, not implementation. I (as a client) don't care whether you implemented the builder pattern or the factory pattern.
Not only the class name looks bad, it also tells nothing about what it does. It's name is based on its implementation and internal structure.
I rarely use a pattern name in a class, with the exception of (sometimes) Factories.
Edit:
Found an interesting article about naming on Coding Horror, please check it out!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With