static void Main(string[] args) { ObjectStructure o = new ObjectStructure(); o.Attach(new Man()); o.Attach(new Woman()); Success v1 = new Success(); o.Display(v1); Failing v2 = new Failing(); o.Display(v2); Amativeness v3 = new Amativeness(); o.Display(v3); Marriage v4 = new Marriage(); o.Display(v4); Console.Read(); }
static void Main(string[] args) { SampleObjectStructure sampleObjectStructure = new SampleObjectStructure(); sampleObjectStructure.Attach(new Man()); sampleObjectStructure.Attach(new Woman()); // 成功時的反應 Action success = new Success(); sampleObjectStructure.Display(success); // 失敗時的反應 Action failing = new Failing(); sampleObjectStructure.Display(failing); // 戀愛時的反應 Action amativeness = new Amativeness(); sampleObjectStructure.Display(amativeness); // 結婚時的反應 Action marriage = new Marriage(); sampleObjectStructure.Display(marriage); Console.WriteLine(); ObjectStructure objectStructure = new ObjectStructure(); objectStructure.Attach(new ConcreteElementA()); objectStructure.Attach(new ConcreteElementB()); Visitor concreteVisitor1 = new ConcreteVisitor1(); Visitor concreteVisitor2 = new ConcreteVisitor2(); objectStructure.Accept(concreteVisitor1); objectStructure.Accept(concreteVisitor2); Console.ReadLine(); }