views:

218

answers:

6

I need to compose some tasks (problems) for students who learn design patterns.

Please suggest me some practical short-term tasks that would help students understand the theory.
I need some interesting ideas for creational design patterns.

Thanks!


Will be great if you share your experience: when a particular design pattern perfectly fitted in your design.

+2  A: 

I suppose that you should just come up with some scenarios and ask the students which design pattern(s) they would use for each.

For example: We have a object that represents a File and has methods open and close. We want to optionally log a message whenever the application calls open or close.

Another example: We have a downstream system that responds very slowly. We want to design a component that will queue up requests for the downstream system and feed them one by one in the background.

Willis Blackburn
+2  A: 

If you could think of a project that might use many patterns at various points that could give them something a little more meaty to learn with, while at the same time teaching patterns in turn. I'm thinking of something like a simple HTTP server, where you might apply patterns in the request handling, logging, session maintenance, all of that kind of stuff, so you could teach different ones as individual topics but come out with a relatively well structured whole and one that gives practical experience of using the various patterns you're exploring and of their interaction.

glenatron
+1  A: 

Follow Up to the comment:

My original intent was just to suggest a problem domain whereby you could break each part of the entire system into more meaningful portions whereby the students could clearly see a need for each pattern. I figured instead of several unrelated tasks you could follow this idea for several larger tasks and let them see how it would all work together. That might be too much for a student now that I think about it and it didn't really address your issue.

Here's a real life example

Sale(Integer_quantity, ICatalogItem _item, IDiscount _discount) implements ITransaction
Refund(Double _amount, IOrderNumber _orderNumer) implements ITransaction

These came about because someone decided to use a magical number "-1" to indicate no sale. You can imagine what happened when people put in a refund for 1 dollar. The IDiscount was, of course, a Strategy pattern to calculate the price of the sale. We had an abstract factory object to create all the sales.

wheaties
Is your idea to share all the components / subsystems among students?
Kniganapolke
well, rather, it is more of an idea to take something large and have them break it down into it's smaller parts. I'd envision this over a few lectures. Let me add an example to the above.
wheaties
+3  A: 

I found examples in book "Head First Design Patterns" very easy to understand yet enough to understand the patterns.

nanda
+1 had a class last semester which used some of the examples from this book.
Grundlefleck
Thanks for the info, good examples are always welcome.
Kniganapolke
+2  A: 

I recently took a class which had a design patterns aspect to it (in a half-semester course, we spent maybe 3-4 weeks going over design patterns).

Many of our practicals, and our coursework consisted of using JHotDraw to explore their use of patterns (as well as how to develop a framework). JHotDraw is a framework for structured drawing editors e.g. directed graphs, or an example we used was for drawing an orrery. There are several patterns which must be understood in order to use JHotDraw. IIRC the creational patterns used included at least Abstract Factory and the Prototype pattern.

It may take a while to identify which parts of JHotDraw are suitable for your course, but the Javadoc does make it helpful, identifying the pattern a class uses and such like.

As stated in another answer, the examples in Head First Design Patterns are also excellent, we used them in our course too (honours year undergraduate level).

Grundlefleck
Thanks for mentioning that open-source project - it can be really helpful for me (although it does take time to analyze all the code and prepare tasks / examples).
Kniganapolke
A: 

While sorting out with JHotDraw I found this academic tool - DP Miner.
It is supposed to analyze the system and search the classes that match some design patterns. It accepts xml (xmi) file that describes the system (the file can be generated by Rational Rose after reverse engineering of the code, I used Enterprize Architect for that). The standalone version of the tool can discover only 4 hardcoded patterns.
The tool is also available as plugin for Eclipse. So this version accepts also xml file that describes a pattern and uses this description to discover it in the system. So the idea is to ask students to create xml descriptions for other patterns and discover them in different systems.
However I spent about 5 hours yesterday trying to get all this working... I managed to get results only from standalone version using their test description file for JHotDraw (I generated my own xml using Enterprise Architect, but there were no results with it). May be later I'll manage to make it work for me and will update this post.

Kniganapolke