I made up this fake project just to point out a few problems that I often encounter. It's a kind of novel generator (in this case but I might want to apply the same model for pictures, music, game elements, etc). Suppose I have stored several chunks of sentences somewhere : A = "I am " B = "going to buy " C = "this dog. " D = "in the shop and " E = "speaking to " F = "this chair. " And a basic model of sentence such as : [A+B+C] A program loads these data and use them to generate a short story : A + B + C = "I am going to buy this dog. " Now I want to store a few rules that specify what chunk could replace each other, for instance object [B] could be replaced either by [E] or by [D+B] so that the final sentence could be : A + E + C = "I am in the shop and going to buy this dog. " or A + D + B + C = "I am speaking to this dog. " So far I could use a classic database. Let's say I'm making it comma separated and inside brackets with a "[ID,sentence_chunk,[possible_replacements]]" structure, that would be : [A,"I am ",[]] [B,"going to buy ",[E,D+B]] [C,"this dog. ",[]] [D,"in the shop and ",[]] Also this could become recursive and the program could decide to replace [B] by [D+B] twice, that would make a sentence such as : A + D + D + B + C = "I am in the shop and in the shop and going to buy this dog. " Recursivity could be a good thing in some cases, but in this particular one it doesn't make much sense. Also, starting with the sentence A + B + F ("I am going to buy this chair. "), the program might want to replace [B] by [E] and I'd like the [E] node to contain some property specifying that a chair is not something you can speak to and it should not do that. Those are just a few examples out of the many cases where a simple database is not enough and I need some scripting associated to it. I'd really like the core of the program to be a simple engine with no subjective data or story at all, it would just recursively and randomly check conditions and set the right replacement if they return true. So any specific scripts like those I'm referring to above should be contained inside the chunks "objects" themselves that would reference each other. I hope it's clear why I want it that way, otherwise I could find a way to explain. --- So one approach could be to use the same language for the "engine" and the scripts, write an abstract Chunk class and extend it in a different way for each chuck (I'm doing it Java style) : class Chunk_B extends Chunk { public String text = "going to buy "; public String possible_replacement = "Chunk_E"; public boolean conditions_for_the_replacement { return parent.the_sentence_that_contains(this).is_about_a_living_thing; } } So this brings many problems : I wrote the possible replacement as a string while it would be more convenient to write it as a kind of pointer to a class (not an object since it might not exist yet in this context) and I don't know how to do that It feels weird to me to have one class for each chunk (since there could be many many chunks at the end). If it's really something people do, is there a naming convention for that kind of case (rather than appending _A, _B, etc to the abstract class name) ? In my current example only one instance of each class needs to be created, but one might eventually have several since a single chunk might appear at various places in the story with some possible variations based on the surrounding words (i.e if I'm constructing it with this.text = "after I bought this " + _word + ", I went back home. "; where the _word could be either "chair" or "dog" passed as an argument). I'm pretty sure there is a better way to handle the "parent.the_sentence_that_contains(this).is_about_a_living_thing" part. What I'd ideally want is that everything, even the very first [A+B+C] sentence model, is contained as a replacement in the same Chunk structure. So that if that chunk structure has a "boolean is_about_a_living_thing = true;" inside it, all the chunks that could replace it would also be considered living unless they specify something else. If I'm ending up with many potential properties such as the "living" one, I do not want to be obliged to specifically assign a value to it in each chunk, but only if it makes sense. I'm giving this example with only one replacement object, but what if there are several ? I suppose I could create a replacement class with the condition and the "pointer" and have an array of those in the Chunk object, but the same problem about how to individually script each replacement would arise. Also, since it's possible that some chunks would contain no script at all, I could have a generic instantiable Chunk class for those rather than an abstract one. Or are there reasons no to do so ? --- Another solution would be to use functions as arguments, I don't know if there is a proper name for that but I'm often using it in javascript, stuff like : // to be placed in the "B" chunk thisChunk.set_one_possible_replacement_to_this_chunk(array(0=>"E") , function(){ return this.parent.are_we_talking_about_a_living_thing; // condition to fulfill for this replacement to occur }); I suppose that would be the best option, I could then have only one class and my "database" would just be made of several constructions with functions passed as arguments that would be called later at the time the story is being generated. I tried to do this in Java (Processing actually) but I can't figure out how to handle that, any clues ? --- Also some people advised me to use LUA, I've never used it before and don't know much about it. Is it a good solution for my case ? And if so, what should I use it with ?