开发者

Practical tasks for students who learn design patterns [closed]

开发者 https://www.devze.com 2022-12-17 01:11 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

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 开发者_JAVA技巧the theory.

I need some interesting ideas for creational design patterns. It would be great if you shared your experience: when a particular design pattern perfectly fit your design.


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


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).


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.


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.


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.


  1. 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.

  2. "C# 3.0 design patterns" by Judith Bishop contains excercises for all of the classical design patterns.

0

精彩评论

暂无评论...
验证码 换一张
取 消