Immutability InAction - How To Recognized It

Object reference is a common topic in software development. I don’t recall ever reading how to recognize it in an actual application outside of the code. So, this is good to add as part of my "Live and Learn" articles. We wrote a custom application for a manufacturer. That application had objects representing factory parts used to assemble widgets. Hand scanners were used to associate specific control numbers to each part and once the part objects got all of their properties populate they were sent off to another part of the application for migration into the Account and QA applications.

Because the same part was, at times, used from a box of similar parts with identical control numbers, some part objects got split out into multiples. Pseudo code Stuff now; the original objects are in a collection. A new collection was created with multiple references to one specific original part object. When the time came to scan the control numbers, users reported this. They scanned the first part and then the remaining identical parts showed up pre-scanned. This was correct because there was reference to only one mutable object. The solution was to instantiate new instances of the object class and put that in the second collection. You might declare properties as ReadOnly if possible. Some managed code compilers do not enforce mutability so it is good to recognize these signs also.

No Comments

At Your Service


Contact Us

4729 East Sunrise Drive
Tucson, Arizona 85718

Tel: +1 520 344 4644