Is nesting types considered bad practice?

Posted by Rob Z on Programmers See other posts from Programmers or by Rob Z
Published on 2011-01-11T14:34:23Z Indexed on 2011/01/11 14:58 UTC
Read the original article Hit count: 257

Filed under:
|
|
|

As noted by the title, is nesting types (e.g. enumerated types or structures in a class) considered bad practice or not? When you run Code Analysis in Visual Studio it returns the following message which implies it is:

Warning 34 CA1034 : Microsoft.Design : Do not nest type 'ClassName.StructueName'. Alternatively, change its accessibility so that it is not externally visible.

However, when I follow the recommendation of the Code Analysis I find that there tend to be a lot of structures and enumerated types floating around in the application that might only apply to a single class or would only be used with that class. As such, would it be appropriate to nest the type sin that case, or is there a better way of doing it?

© Programmers or respective owner

Related posts about best-practices

Related posts about design