Mind Your Access Modifiers

Here’s good article about the nuances of access modifiers in the .NET CLR. It’s good review and a quick read, so, uh, review and read it. Welcome to the global Internets, Evan. Good first post!

Adding to this, one of the classic mistakes is the “everything is public” approach noobs tend to take when designing their types. Bad noobs. Bad.

Instead why not consider pessimistically defaulting your access modifiers to internal or private? When you get into things like DDD you’ll often want to make your default constructor private and elect to implement factories as static methods on the type to build up an object with proper variants.

A last thing on access modifiers: why the hell is the default interface template in Visual Studio internal by default. 99% of the time I want a public interface. I’ve been in more than one code demo situation (and called out a few from the peanut gallery) where the person (usually me) forgets to make their interface public and it breaks… momentary pause… oh, it’s internal by default! A minor annoyance but yet another thing you have to remember.

Of course one could create their very own interface template that defaults to public.

Comments (1) left to “Mind Your Access Modifiers”

  1. Evan wrote:

    Thanks for the plug! From reading your older posts, I can tell that you are farther down the road I’m on (Agile, DDD, Patterns, etc). I’ll be keeping an eye on your blog.

Post a Comment

*Required
*Required (Never published)