Java Forum / General / July 2006
The Right Level of Patterns
dan.fanelli@gmail.com - 12 Jul 2006 04:26 GMT I sometimes make fun of a buddy of mine for overdoing it with Design Patterns, reading every pattern book he can find and then trying to put all the patterns into his code. I think sometimes patterns are used for the sake of using them, at which point it makes the code more complex than it needs to be. However, when interviewing people, not being able to write a Singleton or Factory sends them right home. Just as a topic of discussion, what is everyone's experiences with this, with confusing code that could be simplified by the right pattern vs. confusing the team by pattern-overuse?
erion.omeri@gmail.com - 12 Jul 2006 07:50 GMT Hi I just graduated from a Computer Science program in the midwest and the only patterns I have "used" was the visitor, in our "Compilers" class. We wrote the MiniJava language using JavaCC. Other than that I just bought Head First's Design Patterns and still have to go over it. I hear a lot of people using the Observer but have not been in touch with any others.
Interesting topic!
> I sometimes make fun of a buddy of mine for overdoing it with Design > Patterns, reading every pattern book he can find and then trying to put [quoted text clipped - 5 lines] > with confusing code that could be simplified by the right pattern vs. > confusing the team by pattern-overuse? IchBin - 12 Jul 2006 08:56 GMT > Hi I just graduated from a Computer Science program in the midwest and > the only patterns I have "used" was the visitor, in our "Compilers" [quoted text clipped - 14 lines] >> with confusing code that could be simplified by the right pattern vs. >> confusing the team by pattern-overuse? Pleas do not top post. It is going to make this thread hard to read...
I like the decorator pattern.. In fact the Head First's Design Patterns book has a nice chapter on it.
Thanks in Advance... IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us __________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
TechBookReport - 12 Jul 2006 09:50 GMT > I sometimes make fun of a buddy of mine for overdoing it with Design > Patterns, reading every pattern book he can find and then trying to put [quoted text clipped - 5 lines] > with confusing code that could be simplified by the right pattern vs. > confusing the team by pattern-overuse? I've been working on a C#/.NET project with some colleagues - their expertise is C#, mine is primarily Java. Sometimes talking at the pattern level just cuts through the details to get to the heart of this issue. Being able to concisely describe a problem and a solution that is independent from the implementation language is a huge bonus.
-- TechBookReport Java - http://www.techbookreport.com/JavaIndex.html
Tim Smith - 13 Jul 2006 12:00 GMT > I've been working on a C#/.NET project with some colleagues - their > expertise is C#, mine is primarily Java. Sometimes talking at the pattern > level just cuts through the details to get to the heart of this issue. > Being able to concisely describe a problem and a solution that is > independent from the implementation language is a huge bonus. And that is why they are called *design* patterns, not *implementation* patterns. It sounds like you get it. Unfortunately, a lot of programmers do not, and horribly confuse the design process with the implementation process.
 Signature --Tim Smith
Chris Uppal - 12 Jul 2006 10:23 GMT > I sometimes make fun of a buddy of mine for overdoing it with Design > Patterns, reading every pattern book he can find and then trying to put > all the patterns into his code. I think sometimes patterns are used > for the sake of using them, at which point it makes the code more > complex than it needs to be. Ugh.
The correct use of patterns is to use them to talk about design. I.e. they provide a quick and easy way to describe some feature of a design which otherwise would require a lot of words to convey.
They have /zero/ role as input to the design process, except in the sense that designing often requires talking about the design, in which case patterns can help the conversation.
(I don't, of course, mean to limit this to actual speech -- they can be used in emails, code comments, chat-sessions, design documents, whiteboard presentations...)
> However, when interviewing people, not > being able to write a Singleton or Factory sends them right home. Yes, that makes sense. Even if the interviewers isn't a pattern-obsessed idiot (too common), it is still desirable for a prospective employee to be able to use the same vocabulary of design as his/her co-workers.
-- chris
Jeffrey Schwab - 12 Jul 2006 13:15 GMT >> I sometimes make fun of a buddy of mine for overdoing it with Design >> Patterns, reading every pattern book he can find and then trying to put [quoted text clipped - 22 lines] > (too common), it is still desirable for a prospective employee to be able to > use the same vocabulary of design as his/her co-workers. +1
(Except that I when I notice I'm using a pattern I've seen before, I sometimes review the GoF book to see whether I'm doing it "right. :)
Oliver Wong - 12 Jul 2006 16:02 GMT >> I sometimes make fun of a buddy of mine for overdoing it with Design >> Patterns, reading every pattern book he can find and then trying to put [quoted text clipped - 19 lines] > emails, code comments, chat-sessions, design documents, whiteboard > presentations...) Another reason it might be handy to learn about DPs is that it might show you a new solution you hadn't thought of before. Before seeing MVC in university, it hadn't occured to me to seperate the model from its representation, for example.
To address the OP: As with everything else in programming, DPs are tools. Use the right tool for the job. Sometimes DPs aren't the right tools.
- Oliver
Chris Uppal - 13 Jul 2006 09:00 GMT > Another reason it might be handy to learn about DPs is that it might > show you a new solution you hadn't thought of before. Before seeing MVC in > university, it hadn't occured to me to seperate the model from its > representation, for example. I don't think I'd go along with that. You don't learn design from patterns. You might learn from the examples which are provided /with/ the patterns -- but you'd learn just as much from the example if all mention of patterns were stripped out.
-- chris
Oliver Wong - 13 Jul 2006 15:41 GMT >> Another reason it might be handy to learn about DPs is that it might >> show you a new solution you hadn't thought of before. Before seeing MVC [quoted text clipped - 8 lines] > you'd learn just as much from the example if all mention of patterns were > stripped out. You seem to be saying that there's something significant in a design pattern above and beyond the design itself. I think that 99% of the design pattern is the design itself. The last 1% is the name associated with that design.
So if someone said it's a good idea to seperate the model from its representation, and never mentioned the term "design pattern", then yes, I agree that you're not missing out on much. But someone could very easily come along and say "Yeah, this is such a well known practice, it has a name: MVC." and you'd get the last 1%.
- Oliver
Chris Uppal - 14 Jul 2006 14:56 GMT [me:]
> > I don't think I'd go along with that. You don't learn design from > > patterns. [quoted text clipped - 5 lines] > You seem to be saying that there's something significant in a design > pattern above and beyond the design itself. No, not really. Somewhat the reverse in fact.
I am saying that the design pattern is much /less/ than a design. It's principle value lies in giving a useful name to something that would otherwise still exist, but be harder to talk about.
As I say, there may be cases where people reading design pattern books have learned new designs -- but they don't learn them from the patterns. The book(s) would be just as valuable (in this way) if all mention of patterns were removed. Indeed I can think of two good books (one /very/ good) where the pattern stuff is practically valueless, but the book is nevertheless well worth reading.
-- chris
Chris Smith - 12 Jul 2006 22:03 GMT > The correct use of patterns is to use them to talk about design. I.e. they > provide a quick and easy way to describe some feature of a design which [quoted text clipped - 3 lines] > designing often requires talking about the design, in which case patterns can > help the conversation. Wow, I'm in about 100% disagreement with you over this. Although patterns tend to play some role in building vocabulary, this is secondary to their purpose, which is to get people to recognize and think about good design practices that have arisen from long experience in a variety of situations. I start to get skeptical when I'm talking to someone who throws around too many design pattern names in conversation.
I also think that using design pattern names as shorthand for discussing designs is potentially limiting in terms of design possibilities. This is, in a sense, a form of Sapir-Whorf for object oriented design. I worry about a book being taken as the specification for "correct" use of a pattern. The book is no more knowledgable than the programmer about the concerns of a specific application. There are many variations in design that might make sense, but that may not be considered if there's too much focus on what pattern is being used. In particular, there is considerable danger that when I use a word to describe a general design idea, someone else may read into that some specific implementation decisions that I didn't intend to convey. This possibility becomes increasingly likely as programmers intensionally try to use design pattern names to convey more meaning. For this reason, I tend to avoid the practice like the plague.
On the other hand, I do think that patterns have an impact on the design process. Specifically, they play a role in learning design. Reading the GoF book on design patterns is sort of an aha! experience for many developers I've spoken to who attribute that book with getting them to start understanding how OO concepts can be used to solve problems. Even outside of that task, good patterns encapsulate ideas that really do come up again and again in software design, so that being aware of them helps when similar situations arise. The problem, of course, is that this only works when you trust your sources of patterns. I tend to think that the GoF book has a pretty high rate of patterns really being "tried and tested" techniques. Other sources are not so good. Patterns that originated in blogs ought be view with extreme suspicion.
> > However, when interviewing people, not > > being able to write a Singleton or Factory sends them right home. > > Yes, that makes sense. Even if the interviewers isn't a pattern-obsessed idiot > (too common), it is still desirable for a prospective employee to be able to > use the same vocabulary of design as his/her co-workers. I would, again, think the opposite. If someone had never heard of a factory, then I might view this with extreme suspicion... but factories have been around much longer than patterns. If someone implemented a factory differently than my favorite patterns book, this would be no problem. Additionally, I'd view never having heard of a "singleton" by an experienced programmer as surprising, but not necessarily a disqualification unless it indicates that the programmer is actually not so experienced.
 Signature Chris Smith - Lead Software Developer / Technical Trainer MindIQ Corporation
Chris Uppal - 13 Jul 2006 10:05 GMT [me:]
> > The correct use of patterns is to use them to talk about design. [...] > > They have /zero/ role as input to the design process, except [...] > > Wow, I'm in about 100% disagreement with you over this. OK.
I just want to pick up on one to two small things.
> I start to get skeptical when I'm talking > to someone who throws around too many design pattern names in > conversation. It seems that your experience of people using patterns has not been like mine. I have met a few people who take "the book" as some sort of Gospel[*] to be followed with relentless accuracy. I hope it's obvious that I don't mean patterns (or pattern volcabulary) should be used like that -- e.g. I'd view with some suspicion anyone who actually remembered the difference between the various flavours (in GoF) of adaptor. And, pedant though I am, I would disaprove strongly of anyone who diverted a discussion of what a design /was/ into a discussion of what it should be /called/. But, my experience of patterns has largely been positive.
([*] I believe I have mentioned before an ex-collegue who liked to keep a copy of GoF at his desk so that he could "get the method names right"...)
> I also think that using design pattern names as shorthand for discussing > designs is potentially limiting in terms of design possibilities. This > is, in a sense, a form of Sapir-Whorf for object oriented design. ;-)
-- chris
John Gagon - 15 Jul 2006 22:36 GMT > > I sometimes make fun of a buddy of mine for overdoing it with Design > > Patterns, reading every pattern book he can find and then trying to put [quoted text clipped - 11 lines] > designing often requires talking about the design, in which case patterns can > help the conversation. I find that people portray arrogance by deferring too much real conversation when the design phase is occuring. It makes them look managerial and "big picture" and "open". (brains pouring out open).
It is fine to defer solutions of course when talking requirements or a certain level of specifications but often, as you mention, talking about the design, often the design that already exists seems appropriate. When talking about a new design, it is good to make decisions quickly...however, it seems equally important to remember that no single design should be instant solution and that it is good to get two or more on the table sometimes and pick the best one. That is sometimes why people seem to not want to talk about a particular pattern is so that they can keep the implementation idea open. However, too often, it is because they have already decided against it. Constantly keeping options open is not "pragmatic" and is part of the "paralysis". Sometimes, a senior developer is good about making a careful decision but over time, they can get paranoid about this and they more than anyone tend to be like this anecdotally from my own experience.
What is very annoying is to try to limit someone's conversation from talking about anything because more often, people bring difference experiences and it is extremely arrogant and narrow minded (ironically) to not listen or to be judgemental about someone's ideas because of particular personality clashes/biases, etc. It is more productive to at least consider options and ideas but also to give everyone some equal amount of time. Otherwise, some people spiral down out of politics when they often have been the type to do tremendously well in other situations where personality was not an issue.
> (I don't, of course, mean to limit this to actual speech -- they can be used in > emails, code comments, chat-sessions, design documents, whiteboard [quoted text clipped - 6 lines] > (too common), it is still desirable for a prospective employee to be able to > use the same vocabulary of design as his/her co-workers. I'd agree there...
I've tended to pick up patterns by doing them and later recognizing them or sometimes playing with one that sounds good and then doing some proof and discovering how well it works. In order, I learned:
Singleton Factory (and how they can help keep a more pure interface like design.) Facade Composite Adapter Observer Decorator Strategy Visitor Memento Little Language (I'm aware of others but haven't had the projects that would make use of them.)
The observer has so many synonymns in the real world that it is the simplest and most confusing at the same time. But it is one I've really started to fall in love with and has almost become a golden hammer of sorts. It has been most appropriate for my latest project.
Aside note without further addressing the OP here, a few anti-patterns I find are useful conversationally but I find they may have more to do with strategy than an implementation tactic other than say "spaghetti". Does anyone own that book? I had talked about it so much without actually owning a book that not long ago, I acquired it just for that reason. It seems again a useful kind of language enhancer. Often, Refactoring and Pattern go hand in hand and refactoring includes the reverse pattern depending on situations. Those might be more truly anti-pattern but strangely, some anti-patterns can be "good patterns" in some scenarios.
> -- chris Chris Uppal - 17 Jul 2006 10:13 GMT > The observer has so many synonymns in the real world that it is the > simplest and most confusing at the same time. But it is one I've really > started to fall in love with and has almost become a golden hammer of > sorts. It has been most appropriate for my latest project. Observer is almost as generic as "Function call" -- a design pattern that has to be implemented by hand in some languages, but is so very useful that it is built in to most current general-purpose languages.
Another extra-ordinarily wide ranging design pattern -- so general that it's hard to think of it as a pattern at all[*] -- is "Extra Level of Indirection".
([*] But experienced practitioners do recognise it, and know it as an old friend to be trotted out as the solution to all sorts of thorny design problems.)
> Aside note without further addressing the OP here, a few anti-patterns > I find are useful conversationally but I find they may have more to do > with strategy than an implementation tactic other than say "spaghetti". > Does anyone own that book? I had talked about it so much without > actually owning a book that not long ago, I acquired it just for that > reason. I find that I have a copy on my shelves (assuming you mean the book "Anti-patterns"); I cannot for the life of me remember whether I have ever actually read it...
-- chris
John Gagon - 18 Jul 2006 01:02 GMT > > The observer has so many synonymns in the real world that it is the > > simplest and most confusing at the same time. But it is one I've really [quoted text clipped - 4 lines] > to be implemented by hand in some languages, but is so very useful that it is > built in to most current general-purpose languages. Inversion of control seems it could almost be like that too. You're right and I do pretty much think of "Observer" that way...that is as a "function call" but a reregistered/passive/inverted (?) one perhaps. It gives real world "control" instead of a system forced control, meaning, it adapts to the real world. Event driven programming and the constructs are common in other languages. I've read articles about how it might, in ways, compete with threading. Threading seems most appropriate in this new "multicore" advantage trend.
> Another extra-ordinarily wide ranging design pattern -- so general that it's > hard to think of it as a pattern at all[*] -- is "Extra Level of Indirection". I'm assuming this is aka Delegate or "Wrapper". *laughs* I agree. I think it's like you say with java, there are no "built in constructs" for things common in other languages. (ie: LISP macros etc etc). The only reason the patterns exist at all perhaps is because of multiple "types" filling various "common roles".
> ([*] But experienced practitioners do recognise it, and know it as an old > friend to be trotted out as the solution to all sorts of thorny design > problems.) Yep.
> > Aside note without further addressing the OP here, a few anti-patterns > > I find are useful conversationally but I find they may have more to do [quoted text clipped - 8 lines] > > -- chris I find too the books on my shelves don't get an end to end reading. Not even this one yet but it's nice to have and perhaps I'll use it someday again since it's generic. A whole lot better than the fluffy "Java Bible" I once got a long time ago. Horrid horrid book.
Ed - 12 Jul 2006 13:58 GMT dan.fanelli@gmail.com skrev:
> I sometimes make fun of a buddy of mine for overdoing it with Design > Patterns, reading every pattern book he can find and then trying to put [quoted text clipped - 5 lines] > with confusing code that could be simplified by the right pattern vs. > confusing the team by pattern-overuse? Design patterns don't really simplify code (except in the sense Chris mentioned, in that they offer a common short-hand vocabulary for solutions). Design patterns are about making code flexible.
Consider both these solutions for simplicity/flexibility:
i) Apple fruit = new Apple();
ii) Fruit fruit = fruitFactory.getFruit(Fruit.APPLE);
.ed
-- www.EdmundKirwan.com - Home of The Fractal Class Composition.
Download Fractality, free Java code analyzer: www.EdmundKirwan.com/servlet/fractal/frac-page130.html
Chris Smith - 12 Jul 2006 23:06 GMT > Design patterns don't really simplify code (except in the sense Chris > mentioned, in that they offer a common short-hand vocabulary for > solutions). Design patterns are about making code flexible. Some design patterns certainly simplify code. For example, using a common manager object to coordinate interactions between a large set of other objects (which GoF calls the Mediator pattern) is a simplifying tool. So are plenty of other patterns.
There's something wrong with saying what "design patterns" do or don't do in terms of specific benefits or goals of design. Different patterns do different things, obviously.
 Signature Chris Smith - Lead Software Developer / Technical Trainer MindIQ Corporation
AndrewMcDonagh - 12 Jul 2006 23:24 GMT > dan.fanelli@gmail.com skrev: > [quoted text clipped - 19 lines] > > .ed A bit of a straw man argument there Ed, unless the code is written a by Pattern Obsessed Dev.
Otherwise, there the AbstractFactory pattern shown above is there for a particular purpose. That purpose being to allow a different form of Apple to be create at runtime, for some purpose.
The is a great way of injecting runtime dynamic changes into the design. Its especially useful for : Frameworks, Unit testing, etc.....
If this dynamic changeability isn't needed, then you wouldn't use the Abstract Factory, you'd just use the standard instantiation approach ('new Apple()' )
> -- > www.EdmundKirwan.com - Home of The Fractal Class Composition. > > Download Fractality, free Java code analyzer: > www.EdmundKirwan.com/servlet/fractal/frac-page130.html dan.fanelli@gmail.com - 13 Jul 2006 01:43 GMT Yep, agree with most of these....I think a lot of the times, often design patterns are simply specific ways of programming to an interface level. Other times, without the book, there are solutions I simply would never have thought of. I remember when first starting java, wondering how the Swing action listeners worked, and probably wouldnt have ever really understood their internals without reading the book. But there is definitely a point of no return, if some pattern book has 50 patterns, none of which a group of seasoned programmers has heard of, then it loses its power for communication and design purposes.
Ed - 13 Jul 2006 08:49 GMT Ed skrev:
<snipped straw man>
Yeah, forget my last post. I was wrong.
Apologies.
.ed
-- www.EdmundKirwan.com - Home of The Fractal Class Composition.
Download Fractality, free Java code analyzer: www.EdmundKirwan.com/servlet/fractal/frac-page130.html
EJP - 14 Jul 2006 01:14 GMT IMO the trouble with design patterns is that they became an instant religion, with two very unfortunate consequences:
(a) little groups sprang up everywhere trying to invent design patterns
(b) lots of books appeared which tried to reduce all of computer science to design patterns.
They *can only be* useful in inverse ratio to their number. The original GoF book is invaluable, and a very few other patterns out of one or two other books.
However here is a true story. Somewhere out there is a pattern called 'Type Object'. It is described in about 28 pages, mostly in terms of a very artificial problem which I don't think a sane programmer would ever encounter - and I've never encountered it either, make of that what you will. Somewhere deep on page one it lists aliases, one of which is 'third normal form'.
Now 3NF can be defined in about 5 lines of text and is a very well known piece of basic relational theory.
Anyway for my sins I was on a patterns mailing list at the time so I wrote a posting entitled something like 'Type Object considered harmful'. I got precisely two responses: one predictable one from the author of 'Type Object' and one from the list owner who invited me to turn my posting into a pattern.
True story.
Chris Smith - 14 Jul 2006 01:37 GMT > IMO the trouble with design patterns is that they became an instant > religion, with two very unfortunate consequences: > > (a) little groups sprang up everywhere trying to invent design patterns Indeed, this is THE problem with design patterns as practiced today,
> (b) lots of books appeared which tried to reduce all of computer science > to design patterns. I haven't seen this. I'd be concerned by it if I saw it.
> They *can only be* useful in inverse ratio to their number. YES! Thanks for saying that. I'm afraid I've been less eloquent so far.
 Signature Chris Smith - Lead Software Developer / Technical Trainer MindIQ Corporation
Chris Uppal - 14 Jul 2006 15:01 GMT > IMO the trouble with design patterns is that they became an instant > religion, with two very unfortunate consequences: They did indeed. For me the point where the madness becomes unmistakable was when they started talking about pattern /languages/ instead of /vocabularies/ -- completely losing any sense of proportion, or of what the value of patterns really is.
I have ranted on this subject before in this group ;-)
But that doesn't make patterns valueless themselves.
> They *can only be* useful in inverse ratio to their number. The original > GoF book is invaluable, and a very few other patterns out of one or two > other books. Agreed entirely. It's a point that seemed to be lost on some of the pattern wanke^H^H^H^H^H^H enthusiasts.
-- chris
Mark Probert - 20 Jul 2006 21:50 GMT >> IMO the trouble with design patterns is that they became an instant >> religion, with two very unfortunate consequences: [quoted text clipped - 3 lines] > instead of /vocabularies/ -- completely losing any sense of > proportion, or of what the value of patterns really is. Just for clarity, this started right at the start, before GoF or any other computer related stuff.
Christopher Alexander published two books on architecture: "A Timeless Way of Building" and "A Pattern Language", that gave the world "design patterns" (they are great to read, BTW). In his definition, "language" can be taken as a lingua franca, a way to describe and talk about specific issues so that there is no misunderstanding.
If you look at his work, it is clear where the GoF have gotten it right, and where many of the later works kind of miss the point.
Regards,
 Signature -mark. (probertm @ acm dot org)
Chris Uppal - 21 Jul 2006 09:39 GMT > > They did indeed. For me the point where the madness becomes > > unmistakable was when they started talking about pattern /languages/ [quoted text clipped - 5 lines] > > Christopher Alexander published two books on architecture: Aaghh! That ****ing architect again.
(Nothing personal ;-)
I regard /any/ mention of him (except very briefly, and only in the introduction to /very/ early works) as another sign that the author has lost it.
> If you look at his work, it is clear where the GoF have gotten it right, > and where many of the later works kind of miss the point. Seems very plausible.
-- chris
Tim Smith - 15 Jul 2006 00:56 GMT > IMO the trouble with design patterns is that they became an instant > religion, with two very unfortunate consequences: [quoted text clipped - 3 lines] > (b) lots of books appeared which tried to reduce all of computer science > to design patterns. Three consequences, at least. What you describe below is another unfortunate consequence.
...
> However here is a true story. Somewhere out there is a pattern called > 'Type Object'. It is described in about 28 pages, mostly in terms of a [quoted text clipped - 11 lines] > author of 'Type Object' and one from the list owner who invited me to > turn my posting into a pattern. (c) People start calling everything they do a "design pattern".
To be a design pattern, something has to come up in fairly common practice, not just one artificial program. The point is that design patterns are solutions to problems that are common, so that they will come up again and again and again, so having a name for them makes for efficient communication. For something like what you are describing with "Type Object", it sounds like no sane person would give a damn about it.
The same misconception that leads to (c) is also responsible for (a). Design patterns are found or noticed, not invented.
 Signature --Tim Smith
Chris Uppal - 15 Jul 2006 10:01 GMT > (c) People start calling everything they do a "design pattern". Slightly related -- or perhaps opposed -- to that is another pattern-related tendency which irritates me. Some people like to claim that patterns indicate an inadequacy in <whatever language>. As if the pattern is being used to work around a lack of expressiveness in that language.
Which is tosh. The pattern is still there, it's just that it is implemented differently at some level. Perhaps the implementation is more-or-less identical, but the expression is neater. Perhaps the implementation is genuinely different. But it is still the same pattern. Code in which it is found is still exemplifying the same design choices.
-- chris
Timo Stamm - 15 Jul 2006 22:18 GMT Chris Uppal schrieb:
> Slightly related -- or perhaps opposed -- to that is another pattern-related > tendency which irritates me. Some people like to claim that patterns indicate [quoted text clipped - 3 lines] > Which is tosh. The pattern is still there, it's just that it is implemented > differently at some level. Of course the pattern is still there, but it might be completely encapsulated in the interpreter/compiler.
For example, in Java 1.4 you are probably using the Iterator Pattern to loop through elements of a collection:
for (Iterator it = collection.iterator(); it.hasNext();) { doSomethingWith(it.next()); }
In PHP, you would use a simpler construct:
foreach ($collection as $element) { doSomethingWith($element); }
Maybe a PHP interpreter does use the Iterator pattern internally, but the programmer never sees it.
As Vassili Bykov wrote: "[...] complex systems implemented in low-level languages cannot avoid reinventing and/or reimplementing (poorly on both counts) the facilities built into higher-level languages."
Timo
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|