I have started a project where I need to design an application that will work as a code-block editor, much like lego mindstorms and this google project. http://code.google.com/p/blockly/
What are the possible approaches for designing such an application in Java?
More specifically, assuming I have one block A, how can I define which other blocks can be connected with it? What I think of is using subclasses and checking the hierarchy, or another possible solution could be some kind of 2D table that will verify a connection is valid(although I think it might get too big?).
p.s: I need to force correct structure of code, and not check it with parser at the end. So only blocks that fit together should be connected.
1
Like any programming language, it’s just a representation of an Abstract Syntax Tree.
Any approach that you can use to represent a tree can be used to represent a program. Interconnecting blocks like you see at Blockly are simply a syntax a human-readable view of an AST. The way the blocks connect make it easier for you to visualise the possible flows for any given item in the tree, and easier to validate on the fly.
I think once you look at it in those terms, the rest is fairly obvious, no? Just code it like you would any tree of classes that can only fit together in particular ways.
3