CSC/ECE 517 Fall 2009/wiki2 18 ee

From Expertiza_Wiki
Revision as of 04:36, 8 October 2009 by Lee (talk | contribs) (→‎The Problem)
Jump to navigation Jump to search

Serialization Proxy Design Pattern

During system design, immutable classes are preferred to guarantee thread safety and consistent object state. For instance, serialization of immutable classes could cause issues in Java if immutability must be preserved. The Serialization Proxy Pattern aims to make serialization acceptable in that regard. Discuss serialization proxy pattern with regards to the problem, design, implementation details, and idiomatic usage.


Introduction

When the need to serialize objects in Java arises, the most common tool is the Serializable interface. This interface is simply used to indicate that the object is serializable. The class may implement the writeReplace() method. If it does, during serialization the object returned from this method will be used for serialization instead of the object itself.

The Problem

One issue with serialization under Java is the need for serialization of immutable classes. Take the following class for example:

 public class person {
    String name;
    Integer age;
    
    public void person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }
    public String name() { return name; }
    public Integer age() { return age; } 
 }


The class is easily serializable with no changes, and could be written to disk easily. A problem arises when the object needs to be deserialized.



http://lingpipe-blog.com/2009/08/10/serializing-immutable-singletons-serialization-proxy/

Definitions

- serialization
- imitable
- 


References