3

In descriptions of Facade and Singleton you can read : "Facade is often implemented as singleton".

I'd like to know when should I implement Facade as singleton and when it is a bad idea.

Marcin Szymczak
  • 11,199
  • 5
  • 55
  • 63

1 Answers1

5

No. It is usually implemented because easier to call, but it gives several disadvantages (added from this answer):

  1. Code coupling
  2. Not-concurrent safe by default
  3. Not Testable

One of the good (bad) point from the link is, it carry the lifetime of the entire application, so it never get disposed. Which can be bad if not control-able from the caller.

Applied especially for framework components.

Community
  • 1
  • 1
Fendy
  • 4,565
  • 1
  • 20
  • 25
  • So when should it be implemented as singleton? Your answer suggests that it should never be a singleton. – Marcin Szymczak Oct 02 '13 at 12:07
  • When you following SOLID principle and TDD, then never do singleton. As stated by this answer: http://stackoverflow.com/a/142450/2155396, singleton only solve 1 problem, that is if you need only one instance for live (such as logging). – Fendy Oct 02 '13 at 12:23