unit 16 iterator

Post on 22-Feb-2016

40 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Unit 16 Iterator. Summary prepared by Kirk Scott. Design Patterns in Java Chapter 28 Iterator. Summary prepared by Kirk Scott. The Introduction Before the Introduction. This chapter is divided into 3 parts: 1. Ordinary Iteration 2. Thread-Safe Iteration 3. Iterating over a Composite - PowerPoint PPT Presentation

TRANSCRIPT

1

Unit 16Iterator

Summary prepared by Kirk Scott

2

Design Patterns in JavaChapter 28

Iterator

Summary prepared by Kirk Scott

3

The Introduction Before the Introduction

• This chapter is divided into 3 parts:• 1. Ordinary Iteration• 2. Thread-Safe Iteration• 3. Iterating over a Composite• I am going to dispense with each part in about

1 overhead

4

Ordinary Iteration

• This refers to the Iterator class with three methods: hasNext(), next(), and remove()

• The Iterable interface, which means a domain class has an iterator() method that returns an iterator on an instance of that class

• For each loops, which allow you to traverse the contents of a collection with an iterator

• This is all standard stuff, and it’s assumed that you are at least generally familiar with it

5

Thread-Safe Iteration

• This is beyond the scope of this course• No doubt it is a fascinating topic, full of tricks

and traps, but if you don’t know what threads are, it’s pointless to talk about iteration in that context

6

Iterating over a Composite

• This is the part of the chapter where the book develops some code, making the classes of the Composite design pattern implement the Iterable interface

• This means also developing a hierarchy of Iterator classes for components, leaves, and composites

• This is relatively complex

7

• As an introduction to iteration as a design pattern it would be better to implement iterability over a simpler programmer developed collection class

• For example, the general idea of a stack came up in the discussion of the Memento design pattern, so that data structure should be familiar

• Keep this in mind as an assignment or test question problem

8

The End

9

• All of the book diagrams for the chapter are tipped in on the following overheads for future reference

• They are not needed in this iteration of the overheads and you’re not responsible for what they contain

10

11

12

13

top related