Python getting become the heart of data analysis works. You can see variety of books…
Recently, while working on one of the Windows Azure migration engagement, we were need to…
Bill Wilder who is a MVP in Windows Azure has taken nice initiative in the…
Previous Parts:
Part 1: Level 0: Vannilla Domain Model
Part 2: Level 1: Constructor & DSL Builder Class
After creating the exam instance, what would be the feasible way for the user to add questions. First, let us see the current API to add questions with the exam() method in ExamBuilder:
ExamBuilder.exam(".NET Fundamentals").AddQuestion(question);
//Exam.cs public Exam question(Question question) { AddQuestion(question); return this; }
//User Mindset: Space1 for defining questions Question q1 = new Question("Expansion of CLR"); q1.AddOption("A", "Common Language Runtime"); q1.AddOption("B", "Common LINQ Runtime"); q1.AddOption("C", "C# Language Runtime"); q1.AddOption("D", "C Language Runtime"); q1.AddAnswers(new string[] { "A" }); Question q2 = new Question("Expansion of CTS"); q2.AddOption("A", "C# Type System"); q2.AddOption("B", "Common Type System"); q2.AddOption("C", "Compiler Test Symbols"); q2.AddOption("D", "CLR Tolerate Service"); q2.AddAnswers(new string[] { "A" }); //User Mindset: Space2 for adding above questions into Exam object ExamBuilder.exam(title: ".NET Fundamentals") .question(q1) .question(q2);
//Exam.cs private static string[] opts = new string[] { "A", "B", "C", "D" }; public Exam question(string description, IListoptions) { Question q = new Question(description); int i = 0; foreach (string option in options) { q.AddOption(opts[i++], option); } return this; }
ExamBuilder.exam(title: ".NET Fundamentals") .question("Expansion of IL", new List{"Indian Language", "Intermediate Language"} );
public Exam question(string description, params string[] options) //Usage .question("Expansion of IL", "Indian Language", "Intermediate Language")
//Exam.cs public Exam question(string desc, Actionoptions) { Question q = new Question(desc); options(q); AddQuestion(q); return this; } //Usage .question("Which one of the following is loaded during a new .NET process creation?", q => { q.AddOption("A", "ILAsm.exe"); q.AddOption("B", "ILDasm.exe"); q.AddOption("C", "MSCorEE.dll"); q.AddOption("D", "MSVCVM.dll"); } )
//Solution 1 - inclusive of Exam, Question ctor, methods used in the usage section below //Question.cs public Question a(string option) { AddOption("A", option); return this; } public Question b(string option) { AddOption("B", option); return this; } public Question c(string option) { AddOption("C", option); return this; } public Question d(string option) { AddOption("D", option); return this; } //Usage ExamBuilder.exam(title: ".NET Fundamentals") .question("Expansion of CLR", q=> { q.a("Common Language Runtime") .b("Common LINQ Runtime") .c("C# Language Runtime") .d("C Language Runtime"); }) .question("Expansion of CTS", q => { q.a("C# Type System") .b("Common Type System") .c("Compiler Test Symbols") .d("CLR Tolerate Service"); }) .question("Which one of the following is loaded during a new .NET process creation?", q => { q.a("ILAsm.exe") .b("ILDasm.exe") .c("MSCorEE.dll") .d("MSVCVM.dll"); } );
Next > |
---|
© 2011 Udooz.net All Rights Reserved.