Visitor Pattern Code Review

Use the Visitor Pattern

Code Review

Code Walkthrough

The Program class creates an instance of the Context class (object) and this is passed to the Course class (object) where the data is parsed.

class Program { static void Main(string[] args) { String rules = "COS333 L2 L2 L2 L2 L2 M25 (L40 T60 ) L10 E55 (L28 T73 ) ";
Context context; Console.WriteLine("{0}\n", rules);
context = new Context(rules); Element course = new Course(context); course.Parse(context);
PrintVisitor visitor = new PrintVisitor(); Console.WriteLine("Visitor 1 - Course structure"); visitor.Print(course);
StructureVisitor visitor2 = new StructureVisitor(); visitor2.VisitAllLabTest(course); Console.WriteLine("\n\nVisitor 2 - Summing the weights\nLabs {0}% and Tests {1}%", visitor2.Lab, visitor2.Test);
Console.Read(); } }

Once the Context data has been parsed, the Course object is visited by the Visitor object and results output.