print · login   

pipeline like in factory :

  • pipeline of machines through which product goes
      `-> easily changable : flexible plugin machines     
  • every machine does something different
        => each machine requires  its own interface on product!!
        => each machine must support "machine interface"  to be  able 
           to get it in the pipeline.
        => by adding machines to a pipeline we construct the whole fabrication process   
  • use interfaces
        define explicitly at product its ways of usages by defining
        several usage interfaces

        define per machine which usage interface it uses of the product

        the machine itself implementa a generic machine interface in which
        it defines how in general it works on products

        using the generic machine interface we can construct a pipeline of machines            


     "Chain of Responsibility" pattern

         http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern

         http://www.tutorialspoint.com/design_pattern/chain_of_responsibility_pattern.htm

details

product implements usageA,usageB interfaces => specifies how product can be used in a machine machineA uses usageA interface => uses it as generic type in the workOn(UsageX) machine method which uses the UsageX specific methods

       interface   Machine  <U extends Usage> {
              public void workOn(U product);
       }  

       class   MachineX  implements Machine<UsageX> {
              public void workOn(UsageX product);
       }    



       you can make list of Machine interfaces          => pipeline
          => can pass Product class to each Machine 


           foreach (  Machine  m  :  list<Machine>    ) {
              m.workOn(product);    ->  if m is machine X then product must implement UsageX interface
           }     

       define explicitly at product its ways of usage  by interface inheritance

          interface Usage {
          }

          interface UsageA extends Usage {

            ..
          }

        class product implements usageA,usageB, {
        }         

         ==> note: overlapping interfaces not a problem!!


      can define per machine the way it usages the product
      the product explicitly defines its usages

      when defining a new machine for pipeline:
         a) let it use on the product usage interfaces
         b) or define new usage interface which product implements
           and let new machine use this usage interface

      one can also define a new pipeline 
      which reuse some of the machines for another product which
      also implements the usages of these reused machines!!