InterviewSolution
| 1. |
How To Serialize Objects With Multiple References? |
|
Answer» When you serialize objects that your program REFERENCES MULTIPLE times, you should write the object only one time. To do this, you can use a hashtable to keep track of the object that you have written. When you write an object for the first time, you add its REFERENCE to the hashtable along with a unique ID value. The ID can be any numeric value. You write the object's CLASS name and ID value to the stream, followed by the object itself. If your program encounters the object a second time, you only write the name of the object and ID value to the stream. When you serialize objects that your program references multiple times, you should write the object only one time. To do this, you can use a hashtable to keep track of the object that you have written. When you write an object for the first time, you add its reference to the hashtable along with a unique ID value. The ID can be any numeric value. You write the object's class name and ID value to the stream, followed by the object itself. If your program encounters the object a second time, you only write the name of the object and ID value to the stream. |
|