Saturday, June 02, 2007

Half a Visitor Pattern is Two Patterns in Mynx Semantic Checks

In implementing the semantic checks for Mynx, the visitor design pattern which is standard software design practice in object-oriented compiler texts. Not using the visitor design pattern seems to be heretical, a heresy against the standard compiler dogma.

However, forcing a design pattern on software implementation is in itself, an anti-pattern. But using the visitor design pattern created more effort than it solved. The crux of that statement seems to be anathema to die-hard advocates of patterns. But there is another point that after some reflection and contemplation, comes to mind.

Two patterns are used in lieu of the visitor design pattern, those are:

1. Facade - look like visitor, and single-point semantic check
2. Singleton - semantic context object, only one for semantic check

For a sentence with a semantic check:

Facade is “check( )” and Singleton is “Context.getContext()”; both patterns are used in tandem, two patterns instead of one, i.e. the visitor design pattern. In use in source code:


//call semantic check with Context object
sentence.check(Context.getContext());

Labels: , , , , ,

Website Spy Software