I want to provide you a pattern I which I thought about a lot in the last days. Comments are appreciated.
Problem
- You have a small object which is data and large set of operations which could be performed to that object
- You want to keep the object’s method list small
- The operations can be done in different ways, including different implementations
- Your small object only knows how to read and save itself from the data abstraction layer
- You want to batch process a number of small objects
Solution
- You have a worker interface which defines the accessor API for the worker and how to add subjects
- You can have multiple workers per subject
- Your worker does the transformation, your subject is transformed
- 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 Design patterns, Patterns, Software design
&
one comment
&
no trackbacks
Trackbacks
Trackback specific URI for this entry
Add a Comment & let me know what you think
mr_spuck means:
published on June 6th 2007, 03:41:55 pmkommt mir irgendwie bekannt vor, ich weiß nur gerade nicht woher …
Reply