Tuesday, February 6, 2007

Decorator Lecture

I certainly had fun in class today. As always, I hoped for more questions, but maybe it's OK. At least you're talking to me now. :)

With today's lecture, I was trying to show you real code for a bunch of examples because the decorator is easy to see, but the details can be strange to follow. You really have to be disciplined about delegating to the inner object because you can't depend on the order in which the decorators will be applied (in other words, no decorator should make assumptions about which things it wraps).

My mom suggested that I force you to talk more during class by making you repeat what I just said. I really don't want to do that because I want you to learn how to ask questions. As an alternative, let me give you a suggestion: any time I say something, you should be asking yourself, "Why is it that way? Could it be any other way? If something changed, how would that affect the pattern?" For example, when I say all of the decorators have to be subclasses of an abstract decorator class, you should be thinking, "Why is the decorator an abstract class? Could it be an interface? What would happen if I had two different categories of decorators? etc." Always be trying to figure out the motivations for and the limits of each pattern we discuss. Maybe that will generate some questions next time!

No comments: