-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
39 lines (25 loc) · 1.29 KB
/
README
File metadata and controls
39 lines (25 loc) · 1.29 KB
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
Item 1: Consider static factory methods instead of constructors
Item 2: Consider a builder when faced with many constructor parameters
Item 3: Enforce the singleton property with a private constructor or an enum type
Item 4: Enforce noninstantiability with a private constructor
Item 5: Prefer dependency injection to hardwiring resources
-> Classical by the use of constructor (or static factory, builder) or better by the use of a
dependency injection framework
Other variant with Java 8 use a supplier
Mosaic create(Supplier<? extends> tileFactory) { ... }
Item 6: Avoid creating unnecessary objects
Like String s = new String("k");
Boolean.valueOf("true") better than new Boolean(true)
https://www.gamedev.net/articles/programming/general-and-gameplay-programming/finite-state-machines-and-regular-expressions-r3176/
Item 8: Avoid finalizers and cleaners
-> There is no guarantee that at which time they are called (if at all).
Implement AutoClosable instead if you want that the client
Item 7: Eliminate obsolete object references
Have a look at Stack.java, do you find the obsolete reference
Item 9: Prefer try-with-resources to try-f inally
{code}
try (InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst)) {
...
}}
{code}
item10