In Vorbereitung

Java Capstone Series Pt. 1

Angeboten von Dr. Thomas Staubitz, Ralf Teusner

Work Sheet 1

Examples and Exercises

We've collected some examples and exercises for you. We already have covered some of these in the videos, so you just can follow the steps. There are also others that you need to solve on your own. These exercises are non-graded, so it's completely up to you if you want to work on them or not.

We've started a separate discussion thread for each of these exercises, please use these threads to discuss your findings/problems/ideas with this particular exercise. Please, do not hi-jack these discussions for off-topic posts to keep them focussed. There's plenty of room for other discussions in the forum.

Download Examples and Exercises

You'll find all listed examples on GitHub:

Counter 1 - Basic MVC example

//TODO

  1. Examine project in detail and get familiar with the code
  2. Refactor
    a. The Views currently pull the new state from the Model, make the Model push its state to the Views.
    b. Get rid of the reference to the Model in the Views.
  3. Discuss your findings/problems/ideas in the forum

This is basically what we did in the videos:

You'll find the starting point for this in the capstone1-counter1 example on GitHub.

You'll find a solution for this in the capstone1-counter2 example on GitHub.

See also these diagrams that show the changes:

Before:

MVC pull

After:

MVC push

Counter 2 - Additional views and strategies

//TODO

  1. Add additional views
  2. Add multiple strategies for the controller: Whenever the mouse is clicked the controller should change its behavior. E.g. move the rectangle ten pixels to the right, next time move it 30 pixels, then ten again, and so on, and so on... Start with a "naive" solution (not using patterns)
  3. Refactor: Apply the Strategy pattern to solve this better
  4. Discuss your findings/problems/ideas in the forum

We did step 1 in the video:

As a reminder, here's a diagram for the Strategy pattern:

Strategy pattern diagram

This diagram shows the example with multiple views:

MVC multiview push

You'll find the starting point for this in the capstone1-counter2 example on GitHub (or just continue with the previous example).
You'll find a solution for this in the capstone1-counter3 example on GitHub.