You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+35-7
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
## Object-oriented design and implementation of a Design Pattern Code Generator.
2
2
This project is the implementation of a program that generates the implementation code of the 23 Gang of Four(GoF) design patterns, as presented in the book “Design Patterns: Elements of Reusable Object-Oriented Software”.
3
3
4
+
------
5
+
4
6
## Index
5
7
6
8
1. About Design Patterns
@@ -45,6 +47,8 @@ The 23 Design Patterns are classified into 3 main categories:
45
47
* Template
46
48
* Visitor
47
49
50
+
------
51
+
48
52
#### 2. About JavaPoet
49
53
50
54
[JavaPoet](https://github.com/square/javapoet), a successor to [JavaWriter](https://github.com/square/javapoet/tree/javawriter_2), is a Java API for generating .java source files. It can generate primitive types, reference types (like classes, interfaces, enumerated types, anonymous inner classes), fields, methods, parameters, annotations, and Javadocs.
The most recent version of JavaPoet available as of now is 1.12.1.
92
96
97
+
------
98
+
93
99
#### 3. Application Design
94
100
95
101
To implement Design Pattern Code Generator(DePaCoG), I have employed the **Factory Method**, **Template Method** and **Singleton** design patterns.
@@ -244,6 +250,14 @@ public class DePaCoG {
244
250
* Sometimes singleton pattern can hide bad code design
245
251
* It requires modifications to be used in a multi threaded environment to make sure multiple instances are not created by multiple threads
246
252
253
+
------
254
+
255
+
The image below shows a class diagram for the complete application. For simplicity I have selected only 3 design pattern classes (each representing its category of design patterns) out of the 23.
The class `DePaCoG` has the main() method in it. It creates an instance of class `Hw1DesignPatternGenerator` (concrete implementation of `DesignPatternGenerator` ). Methods here are for displaying menu of design patterns and getting choice of design pattern from user. Depending on user’s choice the corresponding design pattern generating class (implementation of ``DesignPattern`) is instantiated to generate the design pattern source code.
260
+
247
261
248
262
249
263
#### 4. Test Cases
@@ -256,7 +270,7 @@ There are 2 test classes `DesignPatternTest` and `Hw1DesignPatternGeneratorTest`
256
270
* Test Case to verify `generateCode()` returns `JavaFile[]` object
257
271
* Test Case to verify the generated java files are written successfully in the output folder.
258
272
259
-
273
+
------
260
274
261
275
#### 5. Instructions to Execute
262
276
@@ -270,21 +284,27 @@ For command line execution, locate `hw1-assembly-0.1.jar` at `target\scala-2.13`
270
284
271
285
On Windows, the command to run the jar file: `java -jar hw1-assembly-0.1.jar mode`
272
286
273
-
* Executing using default config file, mode = 0:
287
+
* Executing using default config file, then `mode = 0`:
288
+
274
289
* run `java -jar hw1-assembly-0.1.jar 0`
275
290
276
-
* Executing using custom inputs from user, mode = 1:
For execution in IntelliJ, use `run 0` or `run 1` for the preferred way of execution (argument passed has similar purpose like in the command line method)
280
300
281
301
The output java files are saved under the package name provided in the config file (or as custom input) in a folder named `outputs`. The `outputs` folder is created in the current working directory during execution.
282
302
283
-
303
+
------
284
304
285
305
#### 6. Results of Execution
286
306
287
-
While executing the Design Pattern Code Generator, the main() method in class DePaCoG is executed along with a command line argument (0 or 1). The command line argument is to select whether inputs will be entered via a configuration file or via inputs through the interactive environment.
307
+
While executing the Design Pattern Code Generator, the main() method in class `DePaCoG` is executed along with a command line argument (`0` or `1`). The command line argument is to select whether inputs will be entered via a configuration file or via inputs through the interactive environment.
288
308
289
309
Here is an example of config values to create Abstract Factory design pattern.
290
310
@@ -298,9 +318,17 @@ Here is an example of config values to create Abstract Factory design pattern.
298
318
}
299
319
```
300
320
321
+
For above config input, the output files will be saved at `outputs/com/laptopAbstractFactory`.
322
+
323
+
The classes created are : `Processor.java, Intel.java, AMD.java, OperatingSystem.java, OS.java, ChromeOS.java, Ubuntu.java, LaptopFactory.java, ChromeBookFactory.java,LinuxLaptopFactory.java`
324
+
325
+
The image below shows the class diagram of the classes generated after executing the config input values.
In addition to Abstract Factory, the `default.conf` configuration file also contains inputs for Decorator, Adapter and Observer design patterns.
302
330
303
-
For instance in above config input, the output files will be saved at `outputs/com/laptopAbstractFactory`. The `outputs` folder is created in the current working directory during execution.
331
+
The `outputs` folder is created in the current working directory during execution.
304
332
305
-
The classes created are : Processor.java, Intel.java, AMD.java, OperatingSystem.java, OS.java, ChromeOS.java, Ubuntu.java, LaptopFactory.java, ChromeBookFactory.java,LinuxLaptopFactory.java
0 commit comments