Steven,
thanks for that helpfull reply. It is funny becuase I was just thinking
about the dualism, on the one hand there are these wonderfull elegant
design patterns that supposed to make things easier and on the other
hand it seems like coding has just became harder ever since when I
started applying them. Knowing about them seems sometimes almost a
burden. But the absolute elegance of how they can be used, which is
reflected in the many articles and books on them, just makes me want to
understand them better. And as you say, applying them and failing
horribly is a perfect way to get to know their individual intrisic workings.
Strategy is the one that I am just now looking into, because the
Decorator and the possibilty of not removing them just doesnt make them
suitable for the behaviour I was after on that level.
I have something like this now.
var item = new Item()
item.executeModifier() {
modifier.execute(item.mc)
}
item.setModifier(modifier) this.modifier = modifier
item.setClip(mc) this.mc = mc
Then I will use the Decorator pattern, for decorating (what else) the
items. It so happens that some Items contain text that can be edited.
class ItemTextDecorator implements itemInterface{
_item:Iteminterface
function ItemTextDecorator(item:Iteminterface)
{
_item = item
}
function executeModifier() {
_item.executeModifier(_item.mc)
}
function setModifier(modifier) {
_item.setModifier(modifier)
}
function.setClip(mc) this.mc = mc
//additional function to set Text and edit text
}
It feels beautiful to piece things together like this :)
>Just understand that you won't understand until
> you code yourself into a corner a few times. :)
When will it end, if ever?
"What you're experiencing is premature enlightenment." - Tyler Durden
The Gang of Four specifically warns about this, and it's important to
acknowledge that it's happening.
When people first learn about design patterns, they will immediately
begin looking for places to apply them. They will do this and fail in
some particular way, and in doing so, learn more about that design
pattern or perhaps one that they don't know of, yet. The issue most
people have is trying to solve a problem with a design pattern they just
learned without understanding that it isn't an appropriate pattern.
But, you have to do it wrong in order to learn why. Prepare to fail and
learn from those failures. It will make you a better coder.
Your initial hunch is that your problem would best be solved by the
Decorator pattern, but it very well may not be. The Decorator pattern
has fallen out of favor in recent years, as many people believe it
violates good OOP practices. It has its uses, but they're limited.
You should continue coding this using Decorator if you like, so you can
discover what its limitations are. It sounds like you're already
hitting them. It's possible that Strategy and Composition might be
useful here, as well. Just understand that you won't understand until
you code yourself into a corner a few times. :)
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders