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.

Advertisements