开发者

Is this a common design pattern? "Descriptor pattern"?

Is what I'm doing below a common design pattern? If so, what's the name?

I have a complex object that has "simple" fields like Strings and lists of Strings, as well as other complex objects. I want to add instances of this object to a JMS m开发者_如何学JAVAessage queue, which means they need to be Serializable. I don't want to make the entire object graph Serializable, so I've chosen instead to make "Descriptor" objects that contain the necessary information to build the complex objects and "Builder" objects that can create the objects. Now, I serialize the "Descriptor" object and add it to the queue. When the object is dequeued, it is built into a full-fledged object using the "Builder".

An important note to make is that the objects are jobs that are run on other systems. The message queue is one way and serialization only happens at the beginning of the lifecycle of the job.


The most similar pattern to the one you implemented seems the Memento pattern.

In that case it's used to store the state of an object into a Memento object while anything can modify the original object and allows you to restore the old state by using the Memento as a "previous state" of your object.

In your case you don't need to store a snapshot of the object to modify the original one but just as a lightweight version of the serializable value of itself so it's not exactly the same things but quite similar.


To me this sounds like you implemented (part of) the Memento pattern.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜