CSC/ECE 517 Fall 2009/wiki2 18 ee: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 11: Line 11:
==The Problem==   
==The Problem==   


One issue with serialization under Java is the need for serialization of immutable classes.   
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; }
  }




Line 20: Line 32:


==Definitions==
==Definitions==
- serialization
- imitable
-




==References==
==References==

Revision as of 04:34, 8 October 2009

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; } 
 }



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

Definitions

- serialization
- imitable
- 


References