c# Public Nested Classes or Better Option?

后端 未结 8 667
青春惊慌失措
青春惊慌失措 2020-12-03 05:49

I have a control circuit which has multiple settings and may have any number of sensors attached to it (each with it\'s own set of settings). These sensors may only be used

8条回答
  •  难免孤独
    2020-12-03 06:05

    I don't have too much problem with public nested classes (I'm not a fan of dogmatic rules, in general) but have you considered putting all of these types in their own namespace instead? That's the more common way of grouping classes together.

    EDIT: Just to clarify, I would very rarely use public nested classes, and I probably wouldn't use them here, but I wouldn't completely balk at them either. There are plenty of examples of public nested types in the framework (e.g. List.Enumerator) - no doubt in each case the designers considered the "smell" of using a nested class, and considered it to be less of a smell than promoting the type to be a top-level one, or creating a new namespace for the types involved.

提交回复
热议问题