Wednesday, 18 September 2013

Python design pattern suggestions for type translation

Python design pattern suggestions for type translation

I am teaching myself Python OOP and developing a program to translate
database DDL between DBMS flavours (MSSQL Server, DB2, Oracle and more).
Basically the program takes a DDL file, source DBMS type and target DBMS
type as arguments, and generates target DDL as required. To implement the
behaviour to translate I can only think of a quite long and complex set of
nested if statementst, for example (pseudocode only):
if sourceDBMS is 'a'
if targetDBMS is 'b'
translateAtoB()
if targetDBMS is 'c'
translateAtoC()
if sourceDBMS is 'b'
if targetDBMS is 'a'
translateBtoA()
if targetDBMS is 'c'
translateBtoC()
if sourceDBMS is 'c'
if targetDBMS is 'a'
translateCtoA()
if targetDBMS is 'b'
translateCtob()
Can anyone suggest a pattern that would simplify this logic based on 2
choices of many option types for source & target?

No comments:

Post a Comment