Say we have the following classes: Bakery
, Equipment
, and Batch
. Bakery
is composed of Equipment
like so:
class Bakery
attr_accessor :equipment
end
Equipment
looks like this:
class Equipment
attr_accessor :name, :quantity
end
So to represent a bakery with two ovens we can do this:
ovens = Equipment.new
ovens.quantity = 2
bakery = Bakery.new
bakery.equipment = [ovens]
Now the Batch
class represents one batch of baked goods. It is itself composed of a Formula
with several Step
objects. The Formula
class contains the order of steps and timing information so that Batch
knows when some equipment needs to be used. (I'm leaving out the Formula
and Batch
code for brevity. Full code is available here and here.)
My question is how do I use OOD to temporarily transfer ownership of some equipment (say, 1 oven) from bakery
to batch
. bakery
holds an instance of Equipment
that represents two ovens. One of those ovens is going to be temporarily occupied by a batch
process. Should I create a new instance of Equipment
and pass it to the batch
while decrementing the quantity
of ovens
? Or should I not bother with the quantity
attribute and simply create one instance of Equipment
for each oven in the bakery? In that case I could simply pop the last oven off the bakery.equipment
array and push it onto batch.equipment
until batch
is finished. One business logic requirement is to be able to query future availability of bakery.equipment
. So there needs to be some distinction between the current state (i.e. how many ovens are occupied) and future states (i.e. how many ovens will be occupied at 9:00 PM).
Aucun commentaire:
Enregistrer un commentaire