When good code goes bad…

In my post about refactoring code, I wrote on how you can tell how good a programmer is by looking at his code. That got me to thinking: Some stuff that seems simple, is sometimes hard to remember.

For instance, if you want a class to only have shared methods, you should mark it as not inheritable and set the constructor to private.

Public NotInheritable Class SomeClass Private Sub New() End Sub Public Shared Function SomeMethod() as boolean End Function End Class
The code in C# is like so:
public sealed class SomeClass { private SomeClass() { } public static bool SomeMethod() { } }
Sometimes I get lazy and forget to mark it not inheritable, but lately I’ve been using code analysis, and trying to make my code be more like the .net framework libraries and use best practices.


kick it on DotNetKicks.com
14. January 2009 19:20 by Rick | Comments (0) | Permalink

Comments

About Rick

Rick lives in North Las Vegas. He loves his wife, kids, dog, motorcycle, music and programming. There ain't nothing else. Oh yeah, mountain dew!



Programming interests are geared towards multimedia. Platforms are asp.net, windows forms, and WPF.

Calendar

<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

RecentComments

Comment RSS