Derived from a class many instances that are equal to each other and want to replace them with an object.Convert the value object into a reference object.
Motivation: in many systems, objects can be classified as reference objects and value objects. It is sometimes not easy to select between the referenced object and the value object. Sometimes, you start with a simple value object and save a small amount of unmodifiable data. Then, you may want to add some modifiable data to the object and make sure that any modification to the object affects the place where the object is referenced. At this time, you need to turn this object into a reference object.
Practice: 1. Use replace constructor with factory method (replace constructors with factory functions ).
2, Compilation, and testing.
3The declarative object is responsible for providing access to the new object. It may be a static field or a registry object. You can also use multiple objects as access points for new objects.
4Determine whether these referenced objects are pre-created or should be created with polymorphism. If these referenced objects are pre-created and you must read them from the memory, make sure they are loaded as needed.
5Modify the factory function to return the referenced object. If the object is pre-created, you need to consider: What if someone asks for an object that actually does not exist? You may want to use rename method (function name) for the factory function to send the message that it returns an existing object.
6, Compilation, and testing.