5

Am I the only one that sometimes take the seemingly easy, but wrong, way out of certain design situations? I'll admit I've made my share of questionable Singleton objects. Besides that, I've been known to make a God object or two to make things seem easier.

Do you ever use an anti-pattern even though you know you shouldn't?

Per Stilling
  • 868
  • 2
  • 9
  • 19
  • I'm curious about the singleton. The lazy way out is to just use plain old globals, so why do you go to the extra trouble of using a *more* complex antipattern? Globals might be bad, but they're generally less bad than singletons. And easier to code too. – jalf Feb 20 '09 at 05:17
  • 1
    My belief is that Singletons are inherently a bad design pattern, they are in my opinion only usable in rare hardware driver cases. In most other cases they just introduce global state in my OOP environment which damages design quality goals such as portability. – Per Stilling Feb 20 '09 at 05:28
  • Continued from last comment - However, I often justify singletons by the following logic "I only need one of these so I'll make it a singleton" even though what I really deep inside want is a global variable. – Per Stilling Feb 20 '09 at 05:28
  • 1
    Re singleton; some languages don't allow static interface members - so a singleton is a means to providing static-like methods on an interface (where only an instance can represent an interface). – Marc Gravell Feb 20 '09 at 05:36
  • The real use for singletons vs statics/globals is single point of initialization, but (at least) .NET has you there with the static constructor. – Simon Buchan Feb 20 '09 at 05:53

6 Answers6

6

It is very easy trying to make something flexible, and ending up with the Inner Platform Effect. I'm guilty of inner-databases, for example.

And sometimes it is too tempting to code things yourself rather than use that pre-canned similar version - Not Invented Here. I try to avoid it, but...

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
5

Copy and paste anti pattern

Learning
  • 8,029
  • 3
  • 35
  • 46
2

The God Object anti-pattern is an easy mistake to make. Sometimes it can seem like too much work to break classes up. Then at some point later you pay for it. I have found this anti-pattern goes hand in hand with tight coupling.

The vendor lock-in anti-pattern can also be a hard one to avoid when you're using vendor specific languages.

Chris de Vries
  • 56,777
  • 5
  • 32
  • 27
  • You might want to edit that to say "God". – CTT Feb 20 '09 at 05:13
  • I like the idea of a gob object - all mouth and no trousers one that's complicated but doesn't actually do very much. – Tom Feb 20 '09 at 05:15
  • I actually thought you were using slang. A shame you changed it you could have started a new wave, heh. – Per Stilling Feb 20 '09 at 05:18
  • Unfortunately just a typo. I probably should have read the body of the question before racing away and writing and answer. I now see God Object is also in the question. – Chris de Vries Feb 20 '09 at 05:22
1

you can find more info in SO itself:

What is your “favorite” anti pattern?

What are the most commonly used anti-patterns?

Community
  • 1
  • 1
Gulzar Nazim
  • 51,744
  • 26
  • 128
  • 170
1

In the comments and I think It's warrants being an answer - the Singleton pattern.

It is a way of achieving global variables when a language (such as Java) doesn't support it. This is one of those patterns where you should never use - except when you need it. The important bit is being able to differentiate between when you need to have a global variable (there are instances) and when you just want one.

There are problems with singletons beyond the serious problems of introducing global state, in Java for instance they are only single within the class loader with multiple class loaders you can end up multiple copies.

Tom
  • 43,583
  • 4
  • 41
  • 61
0

Vendor Lock In

There is always that one vendor specific thing that gets added for a specific piece of functionality since it makes more sense than writing it yourself. I've spent much time kicking myself for this decision later on.

Chris Ballance
  • 33,810
  • 26
  • 104
  • 151