← Uz sākumu

Par design patterniem

2004. gada 12. martā, 1 komentārs

I've seen the Iterator pattern applied a few times in PHP. This never made too much sense to me. Often, you really don't need to use it. What the Iterator pattern does is hiding the structure of an aggregate. I don't know about you, but the only aggregate object I tend to use is PHP's array type. Of course I could build my own aggregate objects, but personally I never actually needed to do that to make my application look cleaner and make it more flexible. PHP's array type is very flexible on itself. In a language such as Java, using Iterators makes more sense, since there are many aggregate objects you would naturally choose from, such as Vector, HashMap etc. Such aggregates don't really have a place in PHP world. PHP has a myriad of built-in functions to do array operations, and I just use those. I simply don't see the need for creating an Iterator to provide a uniform way of traversing through object stacks. I simply don't need any more traversal options than PHP provides me with.

Vispār jau labs piemērs, ka, lai projektētu un implementētu labu aplikāciju, nepietiek tikai ar metodikas pārzināšanu.

Tu atbildi augstāk redzamajam komentāram. Atcelt

Gravatar misame

2004. gada 12. martā, plkst. 15:03

heh, nu php vienkārši tik dziļi paslēpj no lietotāja tādas problēmas kā datu struktūras izmērs un novietojums atmiņā, ka pēc iteratoriem tiešām vairs nav nepieciešamības. ;)