creativity is that spark of electricity before an explosion.
it allows us, in a single instance to explore all possibilities without hesitation.
Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.
The classes and/or objects participating in this pattern are:
|
// Interpreter pattern -- Structural example
|
|
using System; using System.Collections; namespace DoFactory.GangOfFour.Interpreter.Structural { // MainApp test application class MainApp { static void Main() { Context context = new Context(); // Usually a tree ArrayList list = new ArrayList(); // Populate 'abstract syntax tree' list.Add(new TerminalExpression()); list.Add(new NonterminalExpression()); list.Add(new TerminalExpression()); list.Add(new TerminalExpression()); // Interpret foreach (AbstractExpression exp in list) { exp.Interpret(context); } // Wait for user Console.Read(); } } // "Context" class Context { } // "AbstractExpression" abstract class AbstractExpression { public abstract void Interpret(Context context); } // "TerminalExpression" class TerminalExpression : AbstractExpression { public override void Interpret(Context context) { Console.WriteLine("Called Terminal.Interpret()"); } } // "NonterminalExpression" class NonterminalExpression : AbstractExpression { public override void Interpret(Context context) { Console.WriteLine("Called Nonterminal.Interpret()"); } } } Output expected:
Called Terminal.Interpret()
Called Nonterminal.Interpret() Called Terminal.Interpret() Called Terminal.Interpret() |
| [+] | .NET Enterprise provides a truly robust and scalable platform to build business applications on I.. |
| [+] | JavaFX goes head to head against Flash and Silverlight in the RIA stakes |
| [+] | Silverlight 2.0 released by Microsoft. Is it a Flash Killer |
| [+] | Microsoft DLR (Dynamic Language Runtime) information released |
| [+] | Java and .NET both bring something to the Enterprise arena |
| [+] | Enterprise Java performance tuning tips |
| [+] | Microsoft adds workflow to cloud-based SOA platform |
| [+] | Privacy Policy |
| [+] | Programming - Design patterns in Software |
| [+] | Running C and Python in browser. Advent of the Low Level Virtual Machine |
| [+] | .NET Framework |
| [+] | Programming - Design patterns in Software |
