I am writing some code that really smells but I can't figure out exactly why.
I have documents that exist in multiple languages. I want to be able to serve a document in its requested language and be able to switch it out for other languages when requested. On my database the documents are separate entries with identical identifiers (
doc_id - which is not a unique value). For instance:
id | doc_id | language | other stuff... --------------------------------------- 1 | 10268 | eng | 2 | 11352 | eng | 3 | 11352 | jpn | 4 | 11352 | ger |
When constructing my document object I am taking a
doc_id and a
language and constructing my object based on the relevant database entry. An issue I can see here is that in the future we might have other modulations of the
document object. Maybe we will want an
abridged or maybe start keeping past versions of the same document. I don't want to couple my object creation with all these variables, and I feel like creating new sub-classes would get muddy, as I would want to combine the types - an old version of an abridged translated document for example.
I feel like this is the kind of problem that could be solved with an elegant pattern, but I lack the experience to pick one out. Any suggestions?