mvonballmo / CSharpHandbook

The focus of this document is on providing a reference for writing C#. It includes naming, structural and formatting conventions as well as best practices for writing clean, safe and maintainable code. Many of the best practices and conventions apply equally well to other languages.
28 stars 5 forks source link

Include section on how to create transient objects #5

Open mvonballmo opened 3 years ago

mvonballmo commented 3 years ago

C# offers support for object-initialization, including init and required properties that allow a user to create immutable objects with a very convenient syntax.

Avoid using factories to create objects that are better created with new().

Drawbacks:

For example, if you have a database layer that lets you create and save objects, an API that returns a new object is not ideal.