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 message 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.
Factory Design Pattern One of the most popular design patterns used by software developers is a factory method. It is a creational pattern that helps create an object without the user getting exposed to creational logic. The only problem with a factory method is it relies on the concrete component.
Although there are 23 design patterns listed in Design Patterns: Elements of Reusable Object-Oriented Software, of those there are 7 that are considered the most influential or important.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With