@@ -22,15 +22,15 @@ All of them try more or less
22
22
* to decouple the "different things" (widgets, forms, business logic, ...) from each other
23
23
* make the "different things" easily testable (unit-testable)
24
24
* try to separate presentation from behaviour
25
- * make the view easily "exchangeable" (e.g. replace Swing with JavaFX)
26
- * concentrate the business logic into e.g. the "model ", which "lives longer" (in years) than the often changing GUI technologies
25
+ * make the View easily "exchangeable" (e.g. replace Swing with JavaFX)
26
+ * concentrate the business logic into e.g. the "Model ", which "lives longer" (in years) than the often changing GUI technologies
27
27
* ...
28
28
29
29
When you develop a Java Swing GUI in practice, you face the following additional challenges
30
30
31
- * how to enforce the proper threading (view elements like JPanel, JButton, ... should be only accessed by AWT-EventDispatchThread)?
32
- * how to keep the view "responsive" by kicking off background actions (-> SwingWorker, new Thread(...), ExecutorService, ...)?
33
- * how to combine the results from multiple asynchronous actions (multiple SwingWorker's, Thread's, Future's, ...) into one result for the view ?
31
+ * how to enforce the proper threading (View elements like JPanel, JButton, ... should be only accessed by AWT-EventDispatchThread)?
32
+ * how to keep the View "responsive" by kicking off background actions (-> SwingWorker, new Thread(...), ExecutorService, ...)?
33
+ * how to combine the results from multiple asynchronous actions (multiple SwingWorker's, Thread's, Future's, ...) into one result for the View ?
34
34
* how to implement Undo/Redo, Validation, Exception-Handling, Timeouts, ...?
35
35
* how to enforce acyclic relationships between "stuff" to get good (isolated) testability?
36
36
* how to deal with backpressure when e.g. the backend is too fast for the frontend and the GUI thread can't keep up?
@@ -72,7 +72,7 @@ image::MVVM_dependencies.png[]
72
72
73
73
* The View "sees" the ViewModel
74
74
* The View "doesn't see" the Model
75
- * The ViewModel "sees" the model
75
+ * The ViewModel "sees" the Model
76
76
* The Model "doesn't see" the ViewModel and "doesn't see" the View
77
77
* We have acyclic dependencies
78
78
@@ -181,7 +181,7 @@ link:./src/main/java/ch/petikoch/examples/mvvm_rxjava/example5[]
181
181
182
182
* Same as Example 4
183
183
* You can cancel the submit processing
184
- * The model has a classic "blocking" API
184
+ * The Model has a classic "blocking" API
185
185
186
186
image::example5.png[]
187
187
@@ -194,7 +194,7 @@ link:./src/test/groovy/ch/petikoch/examples/mvvm_rxjava/example5[]
194
194
link:./src/main/java/ch/petikoch/examples/mvvm_rxjava/example5a[]
195
195
196
196
* Same as Example 5
197
- * The model has a "non-blocking" API, the ViewModel gets simpler
197
+ * The Model has a "non-blocking" API, the ViewModel gets simpler
198
198
199
199
Tests:
200
200
@@ -205,7 +205,7 @@ link:./src/test/groovy/ch/petikoch/examples/mvvm_rxjava/example5a[]
205
205
link:./src/main/java/ch/petikoch/examples/mvvm_rxjava/example6[]
206
206
207
207
* Same as Example 5a
208
- * But with two model API calls running in two different threads
208
+ * But with two Model API calls running in two different threads
209
209
* Waiting for both of them
210
210
* Cancellation for both of them
211
211
@@ -215,12 +215,12 @@ Tests:
215
215
216
216
link:./src/test/groovy/ch/petikoch/examples/mvvm_rxjava/example6[]
217
217
218
- === Example 6a: Form submit with exceptions in model (backend) calls
218
+ === Example 6a: Form submit with exceptions in Model (backend) calls
219
219
220
220
link:./src/main/java/ch/petikoch/examples/mvvm_rxjava/example6a[]
221
221
222
222
* Same as Example 6
223
- * But like in real world, there are sometimes exceptions during e.g. model (backend) method calls
223
+ * But like in real world, there are sometimes exceptions during e.g. Model (backend) method calls
224
224
* How to handle them?
225
225
226
226
This is of course a challenging task: +
@@ -240,8 +240,8 @@ link:./src/test/groovy/ch/petikoch/examples/mvvm_rxjava/example6a[]
240
240
241
241
link:./src/main/java/ch/petikoch/examples/mvvm_rxjava/example7[]
242
242
243
- * The model publishes `LogRow` s (using a computational thread)
244
- * These are added in the view as rows of a `JTable` (using GUI thread)
243
+ * The Model publishes `LogRow` s (using a computational thread)
244
+ * These are added in the View as rows of a `JTable` (using GUI thread)
245
245
246
246
image::example7.png[]
247
247
@@ -255,8 +255,8 @@ link:./src/test/groovy/ch/petikoch/examples/mvvm_rxjava/example7[]
255
255
link:./src/main/java/ch/petikoch/examples/mvvm_rxjava/example7a[]
256
256
257
257
* Same as example 7
258
- * But: The model 's log Observable sometimes fail
259
- * We add some exception handling into the viewmodel , to keey the view alive
258
+ * But: The Model 's log Observable sometimes fail
259
+ * We add some exception handling into the ViewModel , to keep the View alive
260
260
261
261
image::example7a.png[]
262
262
@@ -269,8 +269,8 @@ link:./src/test/groovy/ch/petikoch/examples/mvvm_rxjava/example7a[]
269
269
270
270
link:./src/main/java/ch/petikoch/examples/mvvm_rxjava/example8[]
271
271
272
- * The model uses a threadpool to create plenty of `LogRow` s (using as many threads as there are CPU cores)
273
- * Since the view runs on a single thread, it can't keep up with the pace
272
+ * The Model uses a threadpool to create plenty of `LogRow` s (using as many threads as there are CPU cores)
273
+ * Since the View runs on a single thread, it can't keep up with the pace
274
274
** "Fast producer, slow consumer" kind of problem
275
275
* We need to think about backpressure
276
276
** We could slow down the `LogRow` production (blocking backpressure)
@@ -290,7 +290,7 @@ link:./src/main/java/ch/petikoch/examples/mvvm_rxjava/example9[]
290
290
* So far the views were very static
291
291
* Now we have structural changes at runtime, think of a wizard with it's steps
292
292
* Parts of the views remain static (header, footer)
293
- * Therefore we need some kind of view composition
293
+ * Therefore we need some kind of View composition
294
294
295
295
image::example9.png[]
296
296
0 commit comments