Search code examples
c#.netnaming-conventionsinner-classesparameter-object

Create a regular class or an Inner class for a Parameter Object?


Instead of passing many arguments to a method, I was encapsulating it into an argument object.

note: simplied for demo
alt text

For such a case, what would be a better practice?

• Create a class and name it as InventorySaveArgs?
-- or --
• Create a nested class and name it as SaveArgs?

And would you also explain why one would choose one or the other?

[EDIT]: That argument type will be used in another assemblies, as well.

side question: Just curious, if there is a pattern name for encapsulating multiple parameters to a single object by chance.

[UPDATE]: Found Nested Type Usage Guidelines on MSDN
InventorySaveArgs should be available from another assemblies, so I am going with a regular class.


Solution

  • IIRC .NET Design Guidelines are pretty clear on this - there should be no public nested types.