I'm currently in the process of modelling a generic form of RNA and RNA transcription and I'm having difficulty finding a proper OO modeling of this area.
Human RNA has 4 types of Nucleotides (A, G, U, and C). An RNA strand is just a string of these 4 types. eg, AAGACAUUCUA...
What I'm trying to model is more generic in the sense that I want to be able to decide the number of Nucleotide types at runtime. So, my object model needs to be able to represent an arbitrary number Nucleotide types.
Initially, I thought I'd just have a Nucleotide class which had a int TypeId member. This way, I could have a sequence of Nucleotide instances of arbitrary types... but this doesn't feel right.
I'm not a huge fan of storing type in a variable. I'm also not comfortable with what is essentially definition information being set on every instance (instead of being defined in the a class).
So, how do I get around this? Here's what I've come up with so far:
- On a previous project, we would have Singleton objects which represented another object's type. The other object would simply reference the singleton and that was it. It prevented us from having multiple instantiations of the "definition" of our types. Not too great IMO.
- I remember Entity Framework generating Dynamic Proxies at runtime. I could so something similar. I could have a NucleotideBase base class and, at runtime, define derived classes. I believe this is possible through reflection. I'm not sure what the performance impact is with this approach, but I would assume it's all just one-time overhead when defining the classes.
Are there better, more OO, approaches?