Example #1
0
        public static void TestIterator()
        {
            Console.WriteLine("------------Iterator------------");
            Song song1 = new Song("Jordan Rakei", "Eye to Eye");
            Song song2 = new Song("Billie Eilish", "Bad guy");
            Song song3 = new Song("Tom Misch", "Movie");
            Song song4 = new Song("Jordan Rakei", "Mad world");
            Song song5 = new Song("Jordan Rakei", "Cauliflower");

            Aggregate songsArray = new SongArray();

            songsArray.Add(song1);
            songsArray.Add(song2);
            songsArray.Add(song3);
            songsArray.Add(song4);
            songsArray.Add(song5);

            Aggregate songsList = new SongList();

            songsList.Add(song1);
            songsList.Add(song2);
            songsList.Add(song3);
            songsList.Add(song4);
            songsList.Add(song5);

            IIterator arrayIterator = songsArray.CreateIterator();

            Console.WriteLine("--------------Songs Array------------------");
            for (; arrayIterator.HasNext(); arrayIterator.Next())
            {
                Song song = arrayIterator.CurrentElement();
                Console.WriteLine(song.ToString());
            }

            IIterator listIterator = songsList.CreateIterator();

            Console.WriteLine("--------------Songs List------------------");
            for (; listIterator.HasNext(); listIterator.Next())
            {
                Song song = listIterator.CurrentElement();
                Console.WriteLine(song.ToString());
            }
            Console.WriteLine("----------------------------------");
        }