Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Too many "pattern suffixes" - design smell?

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.

like image 427
finnw Avatar asked Sep 26 '08 00:09

finnw


People also ask

What are code smells and what are the most common types?

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.

What causes code smell?

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.

Is this bad code smell part of the object-orientation taxonomy?

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.

What do coupler code smells like?

Here are some common Coupler Code Smells: 1 Inappropriate Intimacy 2 Indecent Exposure 3 Feature Envy 4 Message Chains 5 Middle Man More ...


1 Answers

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!

like image 61
Pablo Fernandez Avatar answered Nov 03 '22 13:11

Pablo Fernandez