Software design - Lecture 39. The main topics covered in this chapter include: behavioral patterns; category of patterns are concerned with algorithms and assignments of responsibilities between objects; describe not just patterns of objects or classes but also the pattern of communication between them;...
Trang 1Lecture : 39
Trang 2This category of patterns are concerned with algorithms and assignments of responsibilities between objects
They describe not just patterns of objects or classes but also the pattern of communication between them
Trang 3This category will shift the focus from flow of control to concentrate just on the way objects are interconnected
These patterns are concerned with the assignment of responsibilities between objects,
or, encapsulating behavior in an object and delegating requests to it.
Trang 4OR Well Managed Collection
Trang 5 There are different data structure to store data or objects in a collection ie Array, Array list , Vector, stack, link list etc.
In other words there are different container which contain different object and to access the content of each container different mechanism is applied.
Trang 6Arrays are Static data
structure
Vectors are dynamic data structure
list of references to other objects
Since size is fixed memory is
way of storing data
Trang 10Apple
Orange
Banana
Trang 11“The Iterator Design pattern provides a way to access the element of aggregate object sequentially without knowing it’s underlying representation”
Trang 12container in a sequential manner, without having any knowledge about the internal representation of its contents.
the contents of the container.
Trang 13Pattern
Uniform method of accessing elements of collection without knowing the underlying representation
We can write polymorphic code to access the elements of underlying aggregate objects
Trang 14The idea is to take out the responsibility for access and traversal out of the collection and put them in the Iterator Object
Iterator class will define an interface for accessing the element of the collection
Trang 15 The abstraction provided by the Iterator pattern allows you to modify the collection implementation without making any changes outside of collection. It enables you to create a general purpose GUI component that will be able to iterate through any collection of the application.
Trang 16should be designed to provide a public interface in the form of an Iterator object for different client objects to access its contents.
client object to navigate through the list of objects within the container
Trang 17Pattern
Trang 20 Benefits
i Simplifies the interface of the Aggregate by not polluting it with traversal methods
ii.Supports multiple, concurrent traversals
iii.Supports variant traversal techniques
Liabilities
None!
Trang 21 This example is using a collection of books and
it uses an iterator to iterate through the collection
Trang 22Class Diagram