C#, is it okay to use nested classes for logical structure?
The .net Design Guide advises against it:
- "Do not use public nested types as a logical grouping construct; use namespaces for this."
- "Avoid publicly exposed nested types. The only exception to this is when variables of the nested type need to be declared in rare scenarios such as subclassing or other advanced customization scenarios."
That's also what the base class library does: In the System.Web.UI
namespace, you have DataGridItem
, DataListItem
, ListViewItem
, MenuItem
, RepeaterItem
, etc. All of these could be called Item
and nested inside DataGrid
, DataList
, etc. However, this would violate the two principles outlined above.