Creating Objects

Joshua Macy amused at webamused.com
Wed Jan 26 22:34:29 EST 2000


Calishar wrote:
> 
> Hi folks,
> 
>   I'm working on solving a problem that my boss put to me the other
> day, and I have run into a solution that I don't know how to implement
> in Python (or any other language for that matter)
> 
> Basic description of problem (particulars not included)
> 
> Work out a system that can import information from (any number) of
> systems, and write the infomration out (meaningfully) to any system in
> the set.
> 
> I.e.
> Assume a set a set of systems [A-G] the system needs to be able to
> import from any of the seven systems, and write out it back out to any
> of the seven. Ther may or may not be multiple instances of each system
> type.
> 
> What I have in mind is defining a set of base classes and defining the
> actual implementation at run-time
> 
> 

  You haven't said what sort of information the systems provide, but I
would probably approach this by writing a class that represents a
canonical intermediate format, and then a set of translator classes,
each of which is only responsible for translating from a particular
system to the intermediate format or from the intermediate format to the
particular system: conversion can then be perfomed between any two
systems in two steps. That's only nine classes for an 8 system suite
(assuming that you give one class the responsibility for both the to and
the from translation, which seems reasonable in the abstract), and
adding a new system to the suite requires only writing one more to/from
tranlator class.  Deciding just what goes into the intermediate format
and how to represent it could be tricky, but assuming that what your
boss wants is remotely sensible (there is some kind of natural
correspondence of the information of any system to any other system),
you probably already have a pretty good idea of what it might look
like.  I would be tempted to defer deciding absolutely what that entails
by using something like XML as the intermediate format, since I know
that I can get parsing and nicely walkable trees practically for free
using Python's XML tools.

  Joshua



More information about the Python-list mailing list