/* * Klientkoden kallar template-metoden för att utföra algoritmen * Klienten behöver veta vilken konkret klass som används */ public static void ClientCode(AbstractClass abstractClass) { // ... abstractClass.TemplateMethod(); // Denna metod ligger den enda som är synlig utåt och sitter på den abstrakta basklassen // ... }
// The client code calls the template method to execute the algorithm. // Client code does not have to know the concrete class of an object it // works with, as long as it works with objects through the interface of // their base class. public static void ClientCode(AbstractClass abstractClass) { // ... abstractClass.TemplateMethod(); // ... }
public void MakeWords() { parametersGroup.Attach(new Parameter(1, 2.5, "black")); int x = 0; for (int i = 0; i < 9; i++) { if (i <= 2) { Console.WriteLine("FIRST LEVEL"); Word[] list = firstLevel.TemplateMethod(); collection[x] = list[0]; x++; collection[x] = list[1]; x++; collection[x] = list[2]; x++; Composite word = new Composite(list[0].word); Composite letters = new Composite(list[1].word); Composite sentence = new Composite(list[2].word); letters.Add(sentence); word.Add(letters); word.Display(1); collection[x] = new Composite(word.getSequence()); x++; } if (i >= 3 && i <= 5) { Console.WriteLine("SECOND LEVEL"); Word[] list = secondLevel.TemplateMethod(); collection[x] = list[0]; x++; collection[x] = list[1]; x++; collection[x] = list[2]; x++; Composite word = new Composite(list[0].word); Composite letters = new Composite(list[1].word); Composite sentence = new Composite(list[2].word); letters.Add(sentence); word.Add(letters); word.Display(1); collection[x] = new Composite(word.getSequence()); x++; } if (i >= 6) { Console.WriteLine("Third LEVEL"); Word[] list = thirdLevel.TemplateMethod(); collection[x] = list[0]; x++; collection[x] = list[1]; x++; collection[x] = list[2]; x++; Composite word = new Composite(list[0].word); Composite letters = new Composite(list[1].word); Composite sentence = new Composite(list[2].word); letters.Add(sentence); word.Add(letters); word.Display(1); collection[x] = new Composite(word.getSequence()); x++; } } Console.WriteLine(collection[0]); }
/// <summary> /// The client code calls the template method to execute the algorithm. /// Client code does not have to know the concrete class of an object it works with, /// as long as it works with objects through the interface of their base class. /// </summary> /// <param name="abstractClass"></param> private void ClientCode(AbstractClass abstractClass) { // ... abstractClass.TemplateMethod(); // ... }
/// <summary> /// The client code calls the template method to execute the algorithm. /// Client code does not have to know the concrete class of an object it works with, /// as long as it works with objects through the interface of their base class. /// </summary> /// <param name="abstractClass">Abstract class.</param> public static void ProcessSomething(AbstractClass abstractClass) { // Initial operations abstractClass.TemplateMethod(); // Additional operations }
public void TemplateMethodExecuted() { Assert.AreEqual(3, _templateMethod.TemplateMethod()); }
public void ClientCode(AbstractClass abstractClass) { abstractClass.TemplateMethod(); }