Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            #region Exercise 1

            Console.WriteLine("Exercise1");

            INumberVisitor Vis = new NumberVisitor();
            INumber Barry = new MyFloat(2);
            INumber Henk = new MyFloat(3);

            Barry.Visit(Vis);
            Console.WriteLine("");

            #endregion Exercise 1

            #region Exercise 2

            Console.WriteLine("Exercise2");

            IMusicLibraryVisitor MusicLibraryVisitor = new MusicLibraryVisitor();

            ISong HMSong1 = new HeavyMetal("Super Kill");
            ISong JSong1 = new Jazz("Frank Sinatra: The Very Best Of");

            List<ISong> SongList = new List<ISong>();
            SongList.Add(HMSong1);
            SongList.Add(JSong1);

            foreach (ISong Song in SongList)
            {
                Song.Visit(MusicLibraryVisitor);
            }

            Console.WriteLine("");

            #endregion Exercise 2

            #region Exercise 3

            Console.WriteLine("Exercise3");

            IOption<int> TestInt1 = new Some<int>(5);
            IOption<int> TestInt2 = new None<int>();
            I_IntPrettyPrinterIOptionVisitor IntPrint = new IntPrettyPrinterIOptionVisitor();

            string TestString1 = TestInt1.Visit(IntPrint);
            Console.WriteLine(TestString1);

            Console.WriteLine("");

            #endregion Exercise 3

            #region Exercise 4

            Console.WriteLine("Exercise4");

            IOptionLambda<MyFloat> f1 = new NoneLambda<MyFloat>();
            string new_number1 = f1.Visit(x => x.value.ToString(), () => "Nothing here, b0ss.");
            Console.WriteLine(new_number1);

            IOptionLambda<MyFloat> f2 = new SomeLambda<MyFloat>(new MyFloat(5));
            string new_number2 = f2.Visit(x => "The number is " + x.value.ToString() + "! :D", () => "Nothing here, b0ss.");
            Console.WriteLine(new_number2);

            #endregion Exercise 4

            Console.ReadKey();
        }
Ejemplo n.º 2
0
 public void onHeavyMetal(HeavyMetal Song)
 {
     HMSongList.Add(Song);
     Console.WriteLine("Greetings from the MLV!\n\"" + Song.Name + "\" added to \'HeavyMetalSongs\'.");
 }