Structures are usually used for immutable data, for example, a phone number that does not mutate, but instead you get a new one (for example, the number 000 becoming 0001 will mean two separate numbers).
However, pieces of information, such as Name, a string, can either mutate (abc changes its name to abcdef, or gets a new name, for example def). For fields like this, I assume they should be in a mutable class, and not in an immutable structure?
My way of structuring the code is to have an immutable concept, such as Address (any change is the new address completely), in the structure, and then refer to it from a class such as Customer, because the client always has an address. Therefore, I would put CompanyName or Employer in the class as it is modified. But the name can either mutate, or be the same instance 1 or a new name setting, and for now, the company still owns the first name.
Will there be a correct template for assigning a new instance (for example, a new company name, but an old name still owned by the company)?
string name = "";
string newName = new string();
newName = "new";
name = newName;
And mutation is only a standard destination pattern?
thank
source
share