Why use sealed instead of static on a class?
Posted
by
sq33G
on Programmers
See other posts from Programmers
or by sq33G
Published on 2011-11-11T09:19:00Z
Indexed on
2011/11/11
18:26 UTC
Read the original article
Hit count: 291
Our system has several utility classes.
Some people on our team use (A) a class with all-static methods and a private constructor.
Others use (B) a class with all-static methods (these the juniors).
On code analysis, (A) and (B) raise warning CA1052, which recommends marking the class as sealed.
Included in the MSDN documentation there is the following advice:
If you are targeting .NET Framework 2.0 or earlier, a better approach is to mark the type as static.
Why does this make any sense? I would have thought the opposite; AFAIK, previous to 2.0 there was no way to mark a class as static.
© Programmers or respective owner