4
I am working on a C# application that requires a row of items of the type Pedido
. Basically whenever a new order is created it is queued and the application shows the orders in sequential order that must be delivered. When an order is finalized it leaves the queue.
For now what I’m doing is basically maintaining a property enum
status in the requested class that when the request is created has value StatusPedido.Enviado
and when the order is delivered has value StatusPedido.Entregue
. The queue therefore only includes items in the sent state.
To persist this, it is not difficult at first. My first idea was to create a property DataModificacao
in the requests and then order the requests by the modification date remembering that queues are "first in first out". Thus, the application reads the requests in the database, sorts and assembles the queue.
So far so good, the problem is this: there is a requirement for users to be able to reorder the queue. This is because sometimes an order that can be delivered faster can be advanced and passed in front of others.
Doing this in the code is easy. Basically it’s just exchanging references and everything works. But and to persist this? Only modification date does not solve more, because when loading the database requests will not have information of which have been advanced. I thought of a new property that has the order ID that should come next, and a property containing a reference to the next order but I don’t know if it’s a good approach, because this seems more a persistence implementation detail than something that is part of the same domain.
Also, an order when it is out of line (or before it is integrated into the queue, or after it is delivered) no longer has that next one, so the next order does not look like a class property Pedido
even though it only makes sense in certain cases.
How can I persist with this sort of thing: a queue that can be reordered and needs to have its ordering persisted?
+1 by default per row. To complement I recommend the [Priority Queue Pattern](link http://msdn.microsoft.com/en-us/library/dn589794.aspx) However, I would not use the date approach. I see no justification.
– Eduardo Xavier
It’s almost precious the second, but it’s good to know that it exists.
– Leonel Sanches da Silva
Extreme environments like stock exchange maybe!! kkk
– Eduardo Xavier
Yes, or other applications requiring millisecond accuracy.
– Leonel Sanches da Silva