/usr/portage

The worker design pattern 1

I want to provide you a pattern I which I thought about a lot in the last days. Comments are appreciated.

Problem



  1. You have a small object which is data and large set of operations which could be performed to that object

  2. You want to keep the object’s method list small

  3. The operations can be done in different ways, including different implementations

  4. Your small object only knows how to read and save itself from the data abstraction layer

  5. You want to batch process a number of small objects

Solution

  1. You have a worker interface which defines the accessor API for the worker and how to add subjects
  2. You can have multiple workers per subject
  3. Your worker does the transformation, your subject is transformed
  4. Your subject is kept light weight

Example


Your ImageBinary object represents the image binary including height and width (metadata is decoupled). You perform various operations on this object like resizing, cropping, scaling.
$image1 = new ImageBinary(array(‘id’ => 1));
$image2 = new ImageBinary(array(‘id’ => 2));
$image3 = new ImageBinary(array(‘id’ => 3));

$worker = new ImageWorker;
$worker->add($image1);
$worker->add($image2);
$worker->add($image3);
$worker->rotate(90);

Related patterns


Manager, Adapter

Filed under , , & one comment & no trackbacks

Trackbacks

Trackback specific URI for this entry

No Trackbacks

Comments

  1. mr_spuck means:
    published on June 6th 2007, 03:41:55 pm *

    kommt mir irgendwie bekannt vor, ich weiß nur gerade nicht woher …

    Reply

Add a Comment & let me know what you think