`
shake863
  • 浏览: 661574 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Design Patterns in ActionScript-Iterator

阅读更多

There is a famous saying in computer science, “Program = Data Structure + Algorithm”. It figures out the importance of how to organize the data and how to deal with the data.

Maybe, in your applications, you care more about how to show the data, because this has much to do with the user experience. However, how to organize the data and deal with the data is also or much more important, because this has much to do with the performance.

 

 

 

Eh, I don’t want to talk about the performance, it is too big. I just want to talk something has a little to do with how to organize the data. In our daily programming, we will use array, list, or set to store the data. If you want to know the differences between these structures, you’d better to find a textbook in this field.

Array, list and set have their own way to store the data. The array uses continual space to store the data, while the other two using disjunction space to store the data. The difference in storing the data, leads the difference on locating the data. Find the n-th element in array will be much different from the same operation in list or set.

In general, we will write some concrete class for these structures. But, sometimes, we need to access the data without considering the concrete data structure. Or sometimes, we need to define another method for traversing the data.

If you have the requirements like mentioned above, I think you can take a look at this pattern, Iterator. The intent is as follows.

Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

n By THE GOF BOOK

 

Here, I will show you a simple example to illustrate this pattern. In this example, I will just use the array, and provide a backward traverse.

The definition of Iterator is as follows.

  1. interface Iterator
  2. {
  3. function   first () : void
  4. function   next () : void
  5. function   hasNext () : Boolean
  6. function   getElement () : Object
  7. }

Also, we define the interface for data structure.

  1. public interface DataStructure
  2. {
  3. function   getIterator () : Iterator
  4. }

Now, we need to implement the concrete class of the data structure and the iterator. Actually, the concrete iterator knows the details of the specific data structure. And how to traverse the data is depends on the concrete iterator’s implementation. See the code for more information, ‘coz I don’t want to put so much code here :)

Here is the class diagram.

clip_image001

In this pattern, we can traverse the data without considering the concrete data structure by using the same interface, further more, we can change the way of traversing the data by changing the concrete Iterator class.

Search-256x256 Demo | Download Download Full Project

Enjoy!

分享到:
评论

相关推荐

    Go Design Patterns for Real-World Projects epub

    Go Design Patterns for Real-World Projects 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Go Design Patterns for Real-World Projects azw3

    Go Design Patterns for Real-World Projects 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Data Structures and Algorithms with Object-Oriented Design Patterns in CSharp - Bruno R. Preiss.chm

    Data Structures and Algorithms with Object-Oriented Design Patterns in CSharp - Bruno R. Preiss

    Laracasts - design-patterns-in-php

    "Laracasts - design-patterns-in-php.torrent"则可能是一个BT种子文件,用于通过BitTorrent协议下载整个课程的大型数据包,这通常包括所有视频讲座和其他相关文件。 在课程"设计模式在PHP中"中,你可能会学到以下...

    Design-Patterns-in-Modern-C++

    The topic of Design Patterns sounds dry, academically constipated and, in all honesty, done to death in almost every programming language imaginable—including programming languages such as JavaScript...

    Design Patterns in Modern C++--2018

    Reusable Approaches for Object-Oriented... Work with the behavioral patterns such as chain of responsibility, command, iterator, mediator and more Apply functional design patterns such as Monad and more

    design-patterns-for-humans设计模式中文翻译版

    https://github.com/kamranahmedse/design-patterns-for-humans 中文翻译,实例修改位JAVA代码

    Design-Patterns-In-Kotlin,在kotlin中实现的设计模式.zip

    《Kotlin设计模式实战解析》 在编程领域,设计模式是一种通用、可重用的...开源项目"Design-Patterns-In-Kotlin"则是一个很好的学习资源,它提供了各种设计模式在Kotlin中的具体实现,有助于开发者深入学习和实践。

    Go Design Patterns for Real-World Projects.epub

    Go: Design Patterns for Real-World Projects What You Will Learn: Install and configure the Go development environment to quickly get started with your first program Use the basic elements of the ...

    Java+Enterprise+Design+Patterns+-+Patterns+in+Java+Volume+3

    Java+Enterprise+Design+Patterns+-+Patterns+in+Java+Volume+3Java+Enterprise+Design+Patterns+-+Patterns+in+Java+Volume+3

    Design Patterns in ActionScript

    《ActionScript设计模式》是软件开发领域中针对ActionScript编程语言的一种实践指南,它深入探讨了如何在ActionScript项目中应用经典的设计模式。设计模式是软件工程中的宝贵经验总结,它们是解决常见问题的可复用...

    Pro-Objective-C-Design-Patterns-for-iOS

    《Pro-Objective-C-Design-Patterns-for-iOS》是一本专注于在iOS平台上利用Objective-C语言实现设计模式的专业书籍。书中旨在帮助已经有一定Cocoa开发基础的开发者,通过掌握设计模式的实践应用,提升软件开发的生产...

    2010-13-Design Patterns for Safety-Critical.pdf

    在本论文“2010-13-Design Patterns for Safety-Critical”中,作者Ashraf Armoush探讨了如何将设计模式的概念应用于安全关键嵌入式系统的开发。他构建了一个设计模式目录,这个目录包含了一系列针对硬件和软件的...

    Design Patterns in C#

    design pattern in C# language

Global site tag (gtag.js) - Google Analytics