0

I'm adding Immutable objects support to my Micro ORM called "Symbiotic"

In the case of a create, I need to pass back a newly created version of the value passed in because the object is immutable and I need to update the newly created identity. For non-immutable values I just set the identity property, but obviously I can't do that now. So I'm thinking of adding a new method called CreateImmutable() with a ref for the value and setting the value with the newly created immutable object with the new identity property value and possibly a changed RowVersion property also. The current method return value is the record changed count, so I want the leave that as is.

I know I could take the easy route and force private property setters, but I would rather support pure immutable types.

Does anyone have any thoughts or potential unforeseen issue on my approach?

current method:

public int Create(object value)

proposed new method 1:

public int CreateImmutable(ref object value)

proposed new method 2:

public int CreateImmutable(object value, out object results)
asked Jul 11, 2019 at 17:55
19
  • 3
    I prefer that CreateImmutable actually return an object. That is the "conventional" way of dealing with immutables. Modifying a parameter in-place is suggestive of mutability, not immutability, and if your method always returns 1, there's not much value in returning an int. Commented Jul 11, 2019 at 18:47
  • 1
    If you still want to go this route and preserve your return int, I would prefer using out instead of ref (assuming that I understand correctly what you're trying to do). Commented Jul 11, 2019 at 18:49
  • thanks for the info. Out requires more dev work but does preserve the original value (not sure it's needed?) ref is simpler yet does not preserve original, but the original variable is also ready for more use with the new Id. I agree with you on the return, I will re-evaluate that. ref: stackoverflow.com/questions/1516876/… Commented Jul 11, 2019 at 20:20
  • Also the current api call convention is that the passed-in object is modified. If CreateImmutable returns the new object, it's different than the passed-in object, that seems deceptive to me. A ref or Out is more obvious. Thoughts? Commented Jul 11, 2019 at 20:25
  • 1
    Right. So your "proposed method 2?" Clear as a bell what it does. Commented Jul 11, 2019 at 21:04

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.