IOS Design Pattern Learning (14) iterator

Source: Internet
Author: User

1 Preface
In object-oriented systems, the design pattern for the iterative behavior of abstract sets is called the iterator.

2. Details
2.1 Brief Introduction
The iterator provides a method to access elements in an aggregate object (SET) sequentially without exposing the underlying representation and details of the structure. Elements in a convenient set can only be transferred from the set itself to the iterator object. The iterator defines an interface used to access the collection element and record the current element. Different iterators can execute different traversal policies.

Provides a method to access each element in an aggregate object sequentially without exposing the internal representation of the object.

2.2 category
External iterator: allows the client to directly operate the iteration process. Therefore, the client must know the external iterator before using it.

Internal iterator: A collection object (the target object to be iterated) maintains and operates an external iterator within it. A typical set object of the internal iterator is provided to define an interface for the client, or access an element at a time from the underlying set, or send messages to each element.

2.3 when to use
(1) access the content of the composite object without exposing its internal representation;

(2) The composite object needs to be traversed in multiple ways;

(3) A unified interface is required to traverse various types of composite objects.

3 conclusion
The above is all content and I hope it will help you.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.