0

Possible Duplicate:
Purpose of final and sealed

Hi all,

When should we opt for designing a sealed class?

When should we opt for designing a singleton class?

Community
  • 1
  • 1
ramu
  • 1,019
  • 3
  • 15
  • 41
  • Half of this is a duplicate of http://stackoverflow.com/questions/1450250/purpose-of-final-and-sealed. The other half is a duplicate of countless others. – Jacob Feb 25 '11 at 04:27
  • I prefer dependency injection to singletons in every case I can think of. Dependency injection promotes looser coupling, which makes your code much more unit testable and much easier to change in the future. A singleton is basically a global variable in disguise. – Merlyn Morgan-Graham Feb 25 '11 at 04:30

1 Answers1

0

These are two unrelated uses of a class.

A singleton should be used when you know that you will have exactly one instance of the class during its execution.

A sealed class simply means that it cannot be subclassed (or inherited). I don't know when it is good situation to mark a class as sealed, so I never do.

Gerry
  • 46
  • 1