Assignment 4: Design Patterns

Assignment 4a:

Give a summary description of six design patterns that you choose from the following design patterns: Adapter, Bridge, Builder, Composite, Decorator, Flyweight, Interpreter, Iterator, Mediator, Memento, Observer, Prototype, Proxy, Template Method. In your summaries say: Write a short summary for each of the six patterns, about half a page for each pattern (rather less than more). Do not add diagrams, and do not try to give a complete description of the patterns as found in the books. Rather think of how you would explain the essential ideas of these patterns in a few sentences to a colleague while riding the elevator.

Assignment 4b:

Credit card problem:

You have a file that contains credit card  records. Each record contains a field for the card number, the expiration date, and the name of the card holder. In your system you have the following class structure for the credit cards:
     a class CreditCard,
     classes VisaCC, MasterCC, AmExCC that are all subclasses of CreditCard,
     you assume more subclasses for other credit card types will be added later on.
You now have to design the method(s) (and maybe additional classes) that  reads a record from the file, verifies that the credit card number is a possible account number, and creates an instance of the appropriate credit card class.  What design patterns could you use for that?
Important details: Credit card numbers cannot exceed 19 digits, including a single check digit in the rightmost position. The exact algorithm for calculating the check digit as defined in ISO 2894/ANSI 4.13 is not important for this assignment. You can also determine the card issuer based on the credit card number:
MasterCard First digit is a 5, second digit is in range 1 through 5 inclusive. Only valid lenght of number is 16 digits.
Visa First digit is a 4. Length is either 13 or 16 digits.
AmericanExpress First digit is a 3 and second digit a 4 or 7. Length is 15 digits.
Discover First four digits are 6011. Length is 16 digits.

- Describe what is the primary problem you try to solve.
- Describe what are the secondary problems you try to solve (if there are any).
- Describe what design pattern(s) you use how (use plain text and/or diagrams).
- Describe the consequences of using this/these pattern(s).

Hint: you face here (at least) two problems, one has to do with how you figure out what kind of card a specific record is about, the other one with how you create the appropriate objects. Look at behavioural patterns and at creational patterns.


Assignment 4c:

In assignment 4b you develop a design for the game minesweeper. You can find minesweeper here for Windows. You  can download and play it, the help explains the rules how to play.  This is an assignment about design patterns, so the goal is of course to use some of the patterns you read about. Probably the best  way to do it is to first develop a design, and then to go through the design and check where you could improve the design by using some of the design patterns. Also check where you already automatically have used a design pattern. Keep in mind that in many situations you use several design patterns together. Assume that in the future somebody could extend the system to accomodate some additional rules, or could choose another user-interface, e.g. ,for ascii-terminals or an output-/input-device for blind people, or could introduce a mode where two persons play against each other, or ...  You should not model these things, but try to make the design as maintainable and reusable as possible.

Starting point:



4a has to be done individually. 4b and 4c can be done  in teams of two, and you can just hand in one documentation per team. Design patterns are a tool to discuss designs, so I encourage you to discuss your solutions together also with other teams.