Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

like image 633
Edward Dale Avatar asked Jun 24 '10 12:06

Edward Dale


People also ask

What is the most common design pattern?

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.

Are there more than 23 design patterns?

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.


2 Answers

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.

like image 111
Jack Avatar answered Sep 19 '22 15:09

Jack


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

like image 26
Péter Török Avatar answered Sep 19 '22 15:09

Péter Török