Skip to content

Commit 4ff8fa3

Browse files
committed
Review comments++
1 parent ea7752c commit 4ff8fa3

File tree

4 files changed

+494
-501
lines changed

4 files changed

+494
-501
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,96 @@
1-
/**
2-
* The MIT License Copyright (c) 2016 Amit Dixit
3-
*
4-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5-
* associated documentation files (the "Software"), to deal in the Software without restriction,
6-
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
7-
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8-
* furnished to do so, subject to the following conditions:
9-
*
10-
* The above copyright notice and this permission notice shall be included in all copies or
11-
* substantial portions of the Software.
12-
*
13-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14-
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16-
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18-
*/
19-
package com.iluwatar.module;
20-
21-
import java.io.FileNotFoundException;
22-
23-
/**
24-
* The Module pattern can be considered a Creational pattern and a Structural pattern. It manages
25-
* the creation and organization of other elements, and groups them as the structural pattern does.
26-
* An object that applies this pattern can provide the equivalent of a namespace, providing the
27-
* initialization and finalization process of a static class or a class with static members with
28-
* cleaner, more concise syntax and semantics.
29-
* <p>
30-
* The below example demonstrates a use case for testing two different modules: File Logger and
31-
* Console Logger
32-
*
33-
*/
34-
public final class App {
35-
36-
public static FileLoggerModule fileLoggerModule = null;
37-
public static ConsoleLoggerModule consoleLoggerModule = null;
38-
39-
/**
40-
* Following method performs the initialization
41-
*
42-
* @throws FileNotFoundException if program is not able to find log files (output.txt and
43-
* error.txt)
44-
*/
45-
public static void prepare() throws FileNotFoundException {
46-
47-
fileLoggerModule = FileLoggerModule.getSingleton();
48-
consoleLoggerModule = ConsoleLoggerModule.getSingleton();
49-
50-
/* Prepare modules */
51-
fileLoggerModule.prepare();
52-
consoleLoggerModule.prepare();
53-
}
54-
55-
/**
56-
* Following method performs the finalization
57-
*/
58-
public static void unprepare() {
59-
60-
/* Close all resources */
61-
fileLoggerModule.unprepare();
62-
consoleLoggerModule.unprepare();
63-
}
64-
65-
/**
66-
* Following method is main executor
67-
*
68-
* @param args for providing default program arguments
69-
*/
70-
public static void execute(final String... args) {
71-
72-
/* Send logs on file system */
73-
fileLoggerModule.printString("Message");
74-
fileLoggerModule.printErrorString("Error");
75-
76-
/* Send logs on console */
77-
consoleLoggerModule.printString("Message");
78-
consoleLoggerModule.printErrorString("Error");
79-
}
80-
81-
/**
82-
* Program entry point.
83-
*
84-
* @param args command line args.
85-
* @throws FileNotFoundException if program is not able to find log files (output.txt and
86-
* error.txt)
87-
*/
88-
public static void main(final String... args) throws FileNotFoundException {
89-
prepare();
90-
execute(args);
91-
unprepare();
92-
}
93-
94-
private App() {}
95-
}
1+
/**
2+
* The MIT License Copyright (c) 2016 Amit Dixit
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5+
* associated documentation files (the "Software"), to deal in the Software without restriction,
6+
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
7+
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in all copies or
11+
* substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14+
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18+
*/
19+
package com.iluwatar.module;
20+
21+
import java.io.FileNotFoundException;
22+
23+
/**
24+
* The Module pattern can be considered a Creational pattern and a Structural pattern. It manages
25+
* the creation and organization of other elements, and groups them as the structural pattern does.
26+
* An object that applies this pattern can provide the equivalent of a namespace, providing the
27+
* initialization and finalization process of a static class or a class with static members with
28+
* cleaner, more concise syntax and semantics.
29+
* <p>
30+
* The below example demonstrates a use case for testing two different modules: File Logger and
31+
* Console Logger
32+
*
33+
*/
34+
public final class App {
35+
36+
public static FileLoggerModule fileLoggerModule;
37+
public static ConsoleLoggerModule consoleLoggerModule;
38+
39+
/**
40+
* Following method performs the initialization
41+
*
42+
* @throws FileNotFoundException if program is not able to find log files (output.txt and
43+
* error.txt)
44+
*/
45+
public static void prepare() throws FileNotFoundException {
46+
47+
/* Create new singleton objects and prepare their modules */
48+
fileLoggerModule = FileLoggerModule.getSingleton();
49+
consoleLoggerModule = ConsoleLoggerModule.getSingleton();
50+
51+
/* Prepare modules */
52+
fileLoggerModule.prepare();
53+
consoleLoggerModule.prepare();
54+
}
55+
56+
/**
57+
* Following method performs the finalization
58+
*/
59+
public static void unprepare() {
60+
61+
/* Close all resources */
62+
fileLoggerModule.unprepare();
63+
consoleLoggerModule.unprepare();
64+
}
65+
66+
/**
67+
* Following method is main executor
68+
*
69+
* @param args for providing default program arguments
70+
*/
71+
public static void execute(final String... args) {
72+
73+
/* Send logs on file system */
74+
fileLoggerModule.printString("Message");
75+
fileLoggerModule.printErrorString("Error");
76+
77+
/* Send logs on console */
78+
consoleLoggerModule.printString("Message");
79+
consoleLoggerModule.printErrorString("Error");
80+
}
81+
82+
/**
83+
* Program entry point.
84+
*
85+
* @param args command line args.
86+
* @throws FileNotFoundException if program is not able to find log files (output.txt and
87+
* error.txt)
88+
*/
89+
public static void main(final String... args) throws FileNotFoundException {
90+
prepare();
91+
execute(args);
92+
unprepare();
93+
}
94+
95+
private App() {}
96+
}

0 commit comments

Comments
 (0)