I have an algorithm which creates a collection of objects.  These objects are mutable during creation, since they start out with very little, but then they are populated with data in different places within the algorithm. After the algorithm is completed, the objects should never be changed - however they are consumed by other parts of the software.In these scenarios, is it considered good practice to have two versions of the class, as described below?The mutable one is created by the algorithm, thenOn completion of the algorithm, the data is copied into immutable objects which are returned.
Class with members that are mutable during creation but immutable afterwards
c#
You can perhaps use the builder pattern. It uses a separate 'builder' object with the purpose of collecting the necessary data, and when all data is collected it creates the actual object. The created object can be immutable.