using System; // So I can add new visitors without breaking the oop design, but what // about a new kind of student? public class weirdstudent: stubase, student { public int weirdness; // degree of weirdness public weirdstudent(string n, int w, student nx): base(n,0,nx) { weirdness = w; } public object accept(svisitor v) { if (v is wsvisitor) return ((wsvisitor)v).visit(this); else throw new Exception("this visitor can't visit a weird student"); } }// weirdstudent // note: in order to add a weirdstuent to a list of students, it must // implement interface student. But svisitor doesn't even know HOW // to visit a weirdstudent. public interface wsvisitor : svisitor // can also visit weird students { object visit(weirdstudent x); } // extend auditor lister so it can also visit weirdstudents public class wauditor : auditor, wsvisitor { public wauditor(student s) : base(s) {} public object visit(weirdstudent x) { Console.WriteLine(x.name+" has gpa 0 but weird students are exempt from probation"); current = x.next; return null; } } // alternative to having weirdstudent implement student is to use an // object adapter // public class weirdstudent : stubase ... public class sadapter : student { weirdstudent w; public sadapter(weirdstudent x) {w=x;} public object accept(svisitor v) { if (v is wsvisitor) return ((wsvisitor)v).visit(w); else Console.WriteLine("this visitor can't visit weirdos"); return null; } } // to add a weird student to a list of normal students, must use adapter: // student x = new sadapter(new weirdstudent("dod",30000,a)); /* Compile into stu13b.dll with csc /t:library stu13b.cs /r:stu13.dll */