Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2a77ac2

Browse filesBrowse files
committed
FirstCut++
FirstCut++
1 parent 19cb715 commit 2a77ac2
Copy full SHA for 2a77ac2

8 files changed

+506Lines changed: 506 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎module/README.md‎

Copy file name to clipboard
+29Lines changed: 29 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
layout: pattern
3+
title: Module
4+
folder: module
5+
permalink: /patterns/module/
6+
pumlid: JShB3OGm303HLg20nFVjnYGM1CN6ycTfVtFSsnjfzY5jPgUqkLqHwXy0mxUU8wuyqidQ8q4IjJqCO-QBWGOtVh5qyd5AKOmW4mT6Nu2-ZiAekapH_hkcSTNa-GC0
7+
categories: Persistence Tier
8+
tags:
9+
- Java
10+
- Difficulty-Beginner
11+
---
12+
13+
## Intent
14+
A layer of mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself
15+
16+
![alt text](./etc/module.png "Module")
17+
18+
## Applicability
19+
The module pattern is a design pattern used to implement the concept of software modules, defined by modular programming, in a programming language with incomplete direct support for the concept.
20+
21+
The Module pattern can be considered a creational pattern and a structural pattern. It manages the creation and organization of other elements, and groups them as the structural pattern does.
22+
23+
An object that applies this pattern can provide the equivalent of a namespace, providing the initialization and finalization process of a static class or a class with static members with cleaner, more concise syntax and semantics.
24+
25+
It supports specific cases where a class or object can be considered structured, procedural data. And, vice versa, migrate structured, procedural data, and considered as object-oriented.
26+
27+
## Credits
28+
29+
* [Module](https://en.wikipedia.org/wiki/Module_pattern)
Collapse file

‎module/pom.xml‎

Copy file name to clipboard
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
4+
The MIT License
5+
Copyright (c) 2016 Amit Dixit
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
25+
-->
26+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
27+
<modelVersion>4.0.0</modelVersion>
28+
<parent>
29+
<groupId>com.iluwatar</groupId>
30+
<artifactId>java-design-patterns</artifactId>
31+
<version>1.14.0-SNAPSHOT</version>
32+
</parent>
33+
<artifactId>module</artifactId>
34+
<dependencies>
35+
<dependency>
36+
<groupId>junit</groupId>
37+
<artifactId>junit</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>log4j</groupId>
42+
<artifactId>log4j</artifactId>
43+
</dependency>
44+
</dependencies>
45+
</project>
Collapse file
+73Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 Data Mapper (DM) is a layer of software that separates the in-memory
25+
* objects from the database. Its responsibility is to transfer data between the
26+
* two and also to isolate them from each other. With Data Mapper the in-memory
27+
* objects needn't know even that there's a database present; they need no SQL
28+
* interface code, and certainly no knowledge of the database schema. (The
29+
* database schema is always ignorant of the objects that use it.) Since it's a
30+
* form of Mapper , Data Mapper itself is even unknown to the domain layer.
31+
* <p>
32+
* The below example demonstrates basic CRUD operations: Create, Read, Update,
33+
* and Delete.
34+
*
35+
*/
36+
public final class App {
37+
38+
private static final String OUTPUT_FILE = "output.txt";
39+
private static final String ERROR_FILE = "error.txt";
40+
41+
public static FilePrinterModule filePrinterModule = null;
42+
43+
public static void prepare() throws FileNotFoundException {
44+
filePrinterModule = FilePrinterModule.getSingleton();
45+
46+
filePrinterModule.prepare(OUTPUT_FILE, ERROR_FILE);
47+
}
48+
49+
public static void unprepare() {
50+
filePrinterModule.unprepare();
51+
}
52+
53+
public static final void execute(final String... args) {
54+
filePrinterModule.printString("Hello World");
55+
}
56+
57+
/**
58+
* Program entry point.
59+
*
60+
* @param args
61+
* command line args.
62+
* @throws FileNotFoundException
63+
*/
64+
public static final void main(final String... args)
65+
throws FileNotFoundException {
66+
prepare();
67+
execute(args);
68+
unprepare();
69+
}
70+
71+
private App() {
72+
}
73+
}
Collapse file
+100Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.iluwatar.module;
2+
3+
import java.io.FileNotFoundException;
4+
import java.io.FileOutputStream;
5+
import java.io.PrintStream;
6+
7+
import org.apache.log4j.Logger;
8+
9+
/**
10+
* The MIT License Copyright (c) 2016 Amit Dixit
11+
*
12+
* Permission is hereby granted, free of charge, to any person obtaining a copy
13+
* of this software and associated documentation files (the "Software"), to deal
14+
* in the Software without restriction, including without limitation the rights
15+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16+
* copies of the Software, and to permit persons to whom the Software is
17+
* furnished to do so, subject to the following conditions:
18+
*
19+
* The above copyright notice and this permission notice shall be included in
20+
* all copies or substantial portions of the Software.
21+
*
22+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28+
* SOFTWARE.
29+
*/
30+
public final class FilePrinterModule {
31+
32+
private static final Logger logger = Logger
33+
.getLogger(FilePrinterModule.class);
34+
35+
private static FilePrinterModule singleton = null;
36+
37+
public PrintStream output = null;
38+
public PrintStream error = null;
39+
40+
private FilePrinterModule() {
41+
}
42+
43+
public static final FilePrinterModule getSingleton() {
44+
45+
if (FilePrinterModule.singleton == null) {
46+
FilePrinterModule.singleton = new FilePrinterModule();
47+
}
48+
49+
return FilePrinterModule.singleton;
50+
}
51+
52+
/**
53+
*
54+
* @throws FileNotFoundException
55+
*/
56+
public final void prepare(final String outputFile, final String errorFile)
57+
throws FileNotFoundException {
58+
59+
logger.debug("MainModule::prepare();");
60+
61+
this.output = new PrintStream(new FileOutputStream(outputFile));
62+
this.error = new PrintStream(new FileOutputStream(errorFile));
63+
}
64+
65+
/**
66+
*
67+
*/
68+
public final void unprepare() {
69+
70+
if (this.output != null) {
71+
72+
this.output.flush();
73+
this.output.close();
74+
}
75+
76+
if (this.error != null) {
77+
78+
this.error.flush();
79+
this.error.close();
80+
}
81+
82+
logger.debug("MainModule::unprepare();");
83+
}
84+
85+
/**
86+
*
87+
* @param value
88+
*/
89+
public final void printString(final String value) {
90+
this.output.print(value);
91+
}
92+
93+
/**
94+
*
95+
* @param value
96+
*/
97+
public final void printErrorString(final String value) {
98+
this.error.print(value);
99+
}
100+
}
Collapse file
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
4+
The MIT License
5+
Copyright (c) 2014 Ilkka Seppälä
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
25+
-->
26+
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
27+
<log4j:configuration debug="true"
28+
xmlns:log4j='http://jakarta.apache.org/log4j/'>
29+
30+
<appender name="console" class="org.apache.log4j.ConsoleAppender">
31+
<layout class="org.apache.log4j.PatternLayout">
32+
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
33+
</layout>
34+
</appender>
35+
36+
<root>
37+
<level value="INFO" />
38+
<appender-ref ref="console" />
39+
</root>
40+
41+
</log4j:configuration>
Collapse file
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
import com.iluwatar.module.App;
24+
25+
import org.junit.Test;
26+
27+
/**
28+
* Tests that Data-Mapper example runs without errors.
29+
*/
30+
public final class AppTest {
31+
32+
@Test
33+
public void test() throws FileNotFoundException {
34+
final String[] args = {};
35+
App.main(args);
36+
}
37+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.