in Uncategorized

Considerations for Nested Classes

Shawn Van Ness posted a list called “101 Uses for Nested Classes”. I found it informative so maybe you will too.

Utilty classes is my personal main usage for them, but one use that Shawn didn’t list was to provide concrete implementations of interfaces that don’t require any exposing any public members of their own. The main examples I can think of are IList/IDictionary/ICollection implementations where you provide some kind of specific storage or lazy load implementation. Really nobody ever needs to know about your internal guts and, unless you’re into strongly typing all of yours IList implementations, there’s no reason to expose that class to the outside world. You could obviously accomplish this without nesting the class, but I like it for the strong association it creates with the owner class.

Leave a comment


  • Related Content by Tag