1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
# Topic 1
## Four OOP principles
Abstraction
: Objects can hide implementation details, as with interfaces.
Encapsulation
: Hide internal information from outside, like with getters and setters.
Inheritance
: Classes can extend other classes, inheriting their methods.
Polymorphism
: Speficying interfaces which multiple classes can implement.
# Topic 2
## Class composition
```
A <filled>- B
```
B er en del af A, og B vil ikke kunne fungere alene.
A ejer B.
## Class aggregation
```
A <>- B
```
A har B, men B kan også stå alene.
A bruger B
## Association
```
A --> B
```
A does something with B.
## Exception vs Error
Errors are unrecoverable.
# Topic 3
1. Use cases
Shows interfaction between things.
2. Domain model
3. Interaction diagrams
Shows more detailed interactions as a sequence diagram.
4. Design class diagrams
This repeats multiple times as the requirements may change under development.
This is because unanticipated things might occur.
## Use case
These are pretty much as always, but here are some important words.
Actor
: Who performs operations; a person, organization or computer system.
Scenario
: What are the required interactions required.
Alternate scenario
: What happens if something goes wrong. What can go wrong.
## Requirements
These diagrams are used to get the following requirements.
- Functionality: what should the system do?
- Usability: what kind of UI is needed?
- Performance
- Implementation constraints
Domain rules
: Additional external constraints such as laws etc.
## Domain model
Not a part of design but analysis.
Uses conceptual classes, which are real things not functions or data.
Uses vocabulary of the current domain.
Has associations like, class diagram and are interactions between these real objects.
Examples:
- A is part of B, or is contained in B
- A is a description of B
- A is used by B
- A is owned by B
- A is owned by B
- A is an event affecting B
Only include important association, as this is not a specification.
Can include class attributes, but should not contain complex information.
So a Flight maybe has a destination.
# Topic 5
## GUI
Are:
- Asynchronous
- Components are in containers which are in a layout.
# Topic 8 Interaction and Classes
Creating a design from analysis.
## Mapping objects
Object can be mapped from the interaction design, borrowing names as much as possible.
Objects can have to main responsibilities:
- Doing things
Often methods, ex: Cashier has `scanItem()`.
- Knowing things
## Patterns
Patterns are solution which fit multiple problems, such as having a `Listener`.
### Grasp patterns
General Responsibility Assignment Software Patterns.
Main patterns:
- Information expert:
Assign a task to the class which has the most information about it.
- Creator:
B should create an object if it contains, records, uses, or has information about object.
- Low coupling:
Uses encapsulation to define simple interfaces between classes, and passing data using standard formats.
- High cohesion:
Create focused objects, instead of `god` objects. This can be done by keeping responsabilities related.
- Controller:
Handles system input events, to seperate the interface from the main system.
Coupling and cohesion manage class complexity.
Strike a balance between object size and complexity.
### Visibility
Who can see what.
Should avoid global visibility as much as possible.
Achieved using *information hiding*.
# Topic 9 Design Patterns
Common language between developers.
Always code using interfaces and not classes, always accept interfaces.
Prefer object composition instead of inheritance (why use OOP then).
Patterns can be used when designing, following types:
- Creational: Creates new objects, hiding the creation process
- Structural: Patterns concerning class composition
- Behavioral: Communication between classes
- Anti-patterns: Design features known to create problems
## Factories
Create objects without exposing creation logic.
Eases polymorphism is the factory decides which type to create, and then cast to interface when returning.
## Singleton
An object which is only created once.
Useful when dealing with drivers or sockets.
1. Object A requests singleton C
2. C is creates as it does not exist, and is returned to A
3. B requests C
4. Existing C is returned to B
Special care must be taken when doing multithreading, and testing is also harder.
## Builder
Construct object in the same way as factories.
Implements a `Builder` interface which is run then the product is needed.
One can then build objects without worrying about complex constructor parameters.
## Adapter
Bridge between two incompatible interfaces.
Should be kept as a minimum as deep layering can complicate design.
## Filter pattern
Implements searching.
## Composite
Contains other instances of the same type.
Useful for creating trees.
## Observer pattern
Listens for events and notifies client.
Often used in gui's.
## Publish subscribe
Publishers publish messages, and subscribers can subscribe on specific events.
This is orchestrated by a central broker.
## Some anti patterns
- *God object* with too many responsibilities
- Sequential coupling: methods that must be called in order
- Object orgy: unrestricted access to internal variables
- Yo-yo problem: too many layers of inheritance
- Spaghetti code: too many ad-hoc fixes
- Error hiding
- Object cesspool: reusing objects with unpredictable state
# Topic 10
What happens after first iteration, so first system has been developed.
Clients may want more features.
Here a good domain model can help, as it will facilitate new features easily.
Interfaces can often help implement new features, as only the implementation must be replaced.
## Maintanance
The implementation after a changed design model.
Much easier with a low coupling.
Should be done on a production branch.
# Topic 11
Talking to databases in java happens with the JDBC api.
## ACID
- Atomicity
- Consistency
- Isolation
- Durability
## Testing
Static testing
: Reviewing code.
Dynamic testing
: Unit test, integration test and acceptance test.
### Code review
Single or as a team.
Walk through the code, and become familiar with code.
Often af good way to ensure correct documentation and code style.
### White box testing
Testing with knowledge of implementation.
Path testing
: Does the program reach the correct statements
Data flow testing
: Do variables have expected values at times
Fault injection
: How do methods handle invalid input
Condition/decision testing
: Have all possible outcomes been tested using above
#### Intergration testing
Test modules together, are there any problems.
Bottom-up
: Start with classes, then modules and end at a full program
Top-down
: Start from main method, and gradually add components
### Black box
Should not use knowledge of the implementation.
#### Acceptance testing
Test the different use-cases, from the perspektive of the user.
Often done by external testers.
#### Automated unit test
Run through testcases which run small parts of program.
This is done in java using the j-unit testing framework.
|