Ejemplo n.º 1
0
        // Start is called before the first frame update
        void Start()
        {
            BookShelf bookShelf = new BookShelf(4);

            bookShelf.appendBook(new Book("Around the World in  Days"));
            bookShelf.appendBook(new Book("Bible"));
            bookShelf.appendBook(new Book("Ciderella"));
            bookShelf.appendBook(new Book("Daddy-Long-Legs"));
            Iterator it = bookShelf.iterator();

            while (it.hasNext())
            {
                Book book = (Book)it.next();
                Debug.Log(book.getName());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// イテレータパターン実行
        /// </summary>
        public static void Run()
        {
            BookShelf bookShelf = new BookShelf(); //本棚obj生成

            // 本を追加していく
            bookShelf.appendBook(new Book("エロ本"));
            bookShelf.appendBook(new Book("技術書"));
            bookShelf.appendBook(new Book("マンガ"));

            // この本棚を参照するイテレータを生成する
            IIterator it = bookShelf.Iterator();

            // 要素がなくなるまで繰り返し
            while (it.HasNext())
            {
                Book book = (Book)it.Next();
                Console.WriteLine(book.Name);
            }
        }