[Tutor] Mapping to an equivalent / similar object?

Allen Fowler allen.fowler at yahoo.com
Sun May 31 04:59:29 CEST 2009




> The difference between objects is measeured by their interfaces not their data 
> so provided the supplier objects all use the same operations of a Flavor then 
> its not too bad. You can either create subclasses of Flavor for each 
> manufacturer that retuirns the requisite list of attributes  (but requires 
> ongoing changes for every new manufacturer - eek!) or you can write a method of 
> Flavor that takes a list (or dictionary?) of required attributes and returns the 
> values. It can also raise exceptions if asked for unsupported attributes, or 
> return None, in which case the Supplier object provides a suitable default.
> 

Hmm.  I'll have to read that a couple of times.



> This way you can limit the changes for a new supplier. You might also be able to 
> data drive the Supplier object to make the required list of attributes 
> configurable(via a database or file?). Then you only need subclasses of Supplier 
> for the actual interface types (EDI, v FTP, v http v email etc).
> 
> > How should the mapping between the CanonicalFlavor('Vanilla') object and 
> ManufAFlavor('Vanilla') / ManufBFlavor('Vanilla') objects be handled.
> 
> If the mapping is one to many I don;t think you need to maintain it - at least 
> not in the objects. Just pass the Flavor object to the supplier object. Let the 
> supplier query the Flavor for the data it needs.
> 
> If the choice of supplier was driven by Flavor characteristics then the 
> selection method would be in the Flavour and then you'd need to keep a list of 
> suppliers in the Flavor. But since
> the supplier is chosen from external factors the Flavor doesn't need to know 
> about its supplier. And the supplier only needs to know about how to query a 
> flavour.
> 


What about just Flavor() objects and a customised "per-manufacture" SupplierA() / SupplierB() objects that internally knows how to generate an order from a passed in Flavor() object?  (Which would also raise a CantMakeFlavor error if this manufature can't supply the required flavor.)


      



More information about the Tutor mailing list