I'm working on a game where a player can build some machine from parts. There're couple kinds of parts like engine, manipulator, life-support. Each kind has it's own general rules, for example a manipulator can't be placed directly near an engine. Besides that, each particular part can have special rules, like require at least 5 energy or be connected with life-support.
On top of that, I decided that parts (and their rules) are defined as json file and loaded during gameplay. It'd make game extension/modification trivial, even for non-developers.
I can define atomic rules in code and mention them with logic operators, in json:
{
"rule": {
"or": [
{"and": [{"connected_with": "ENGINE"}, {"min_energy": 5}]},
{"connected_with": "LIFE_SUPPORT"}
]
}
}
Just writing this example, it made me thinking that I.. probably don't need implementation of specification pattern after all.. I've just wrote them with normal Polish notation so it should be feasible to create combined rules in the code.
With specification pattern I could write in code:
rule = (
ConnectedWith("ENGINE").and(MinEngery(5))
).or(Connected_with("LIFE_SUPPORT")
Which is more readable but I have no idea how wanted to parse it to json..
Oh my! Thank you! I should mention my goals in initial post to avoid xy problem.
Also, for some reason, it didn't even cross my mind that I can use multiple languages at the same time (thanks for that also!). As you said, it isn't answer I was looking for, however it should work. With small drawback: cross language inheritance is forbidden.