Skip to content

Commit a52189a

Browse files
Added Main Test file and updated Readme
1 parent cbc177d commit a52189a

File tree

3 files changed

+192
-0
lines changed

3 files changed

+192
-0
lines changed

README.md

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Individual-project-cmpe202-Komal
2+
3+
# Student ID: 016860532
4+
5+
#### 1. Describe what is the primary problem you try to solve?
6+
7+
Ans: The primary problem I'm trying to solve is how to determine whether a credit card is valid or not by comparing it
8+
to the various credit card types, such as Mastercard, Visa, American Express, and Discover, and using the credit card
9+
number to find the card issuer and the appropriate objects based on the type of card.
10+
11+
#### 2. Describe what are the secondary problems you try to solve (if there are any)?
12+
13+
Ans: Determining the appropriate design patterns to take into account is the secondary issue. Future additions of new
14+
credit classes for various credit card types.
15+
16+
#### 3. Describe what design pattern(s) you use (use plain text and diagrams)?
17+
18+
Ans: Design Patterns: Chain of Responsibility, Strategy
19+
20+
###### a) Strategy Design Pattern:
21+
22+
The Strategy Design Pattern enables dynamic behavior changes in an application based on a selected strategy at runtime.
23+
It allows for the creation of objects and strategies specific to different file types, adapting the application's
24+
behavior accordingly.
25+
26+
I implemented Strategy Design Pattern to support multiple file formats in my application. I designed three interfaces -
27+
Reader, Writer, and CreditCardHandler - to handle different aspects of file processing and credit card handling.
28+
29+
The Reader interface provides a common contract for classes that can read input files, and it includes a readFile method
30+
to handle the reading process based on the input file type.
31+
32+
The CreditCardHandler interface defines a common structure for classes responsible for checking the credit card type of
33+
parsed input files. It includes a checkCreditType method that takes the parsed input file and determines if it belongs
34+
to any specific credit card type category.
35+
36+
The Writer interface provides a common structure for classes responsible for writing data to different file formats. It
37+
includes a writeToFile method that takes an input of type OutputEntry (which represents the final output format) and
38+
writes the data to the expected file format.
39+
40+
This design pattern enables runtime behavior swapping and follows the Open/Closed principle. It allows for the
41+
introduction of new strategies without affecting the client code, making it easy to accommodate new file formats without
42+
disrupting the existing code or design.
43+
44+
###### b) Chain of Responsibility Design Pattern:
45+
46+
When a request is issued by the client, it is received by the first handler in the chain. Each handler checks the
47+
request and decides whether to process it or pass it along the chain. If a handler decides not to process the request,
48+
it passes the request to the next handler in the chain. This process continues until the request is handled or the chain
49+
is exhausted.
50+
51+
After parsing an XML, JSON, or CSV file, we need to validate its content to determine the credit card type among the
52+
four available types.
53+
54+
We can utilize the Chain of Responsibility design pattern to validate the file against different credit card handlers.
55+
The validation process starts with the MasterCard handler. If the file does not match the criteria for MasterCard, it is
56+
passed on to the next credit card handler in the chain. This allows for flexible and extensible validation of the file
57+
against multiple credit card types.
58+
59+
To facilitate the overall process, we introduce a main credit card handler that acts as a mediator. This handler
60+
receives the file and passes it to each individual credit card handler for validation. Each credit card handler
61+
implements the main handler and performs the necessary checks specific to its credit card type. This approach enables a
62+
centralized and organized validation process, allowing each handler to focus on its designated credit card type.
63+
64+
#### 4. Describe the consequences of using this/these pattern(s)?
65+
66+
###### a) Strategy Design Pattern:
67+
68+
###### Advantages:
69+
70+
-> The Strategy design pattern provides flexibility in adding new strategies as needed without impacting existing code.
71+
72+
-> It promotes code reusability. By encapsulating specific algorithms or behaviors into separate strategies, these
73+
strategies can be reused across different parts of the application. This eliminates the need for duplicating code or
74+
implementing similar logic multiple times, leading to cleaner and more maintainable code.
75+
76+
###### Disadvantages:
77+
78+
-> Users of the Strategy design pattern should be aware of multiple strategies and understand the distinctions between
79+
them.
80+
81+
-> Having a large number of objects at the same time can become cumbersome and redundant in the Strategy design pattern.
82+
83+
##### b) Chain of Responsibility
84+
85+
###### Advantages:
86+
87+
-> Decouples the sender of a request from its recipients.
88+
89+
-> The client is unaware of the chain structure and interacts with the chain through direct method calls.
90+
91+
-> The order of the chain can be easily modified or adjusted, and new handlers can be added or existing ones can be
92+
removed as needed.
93+
94+
###### Disadvantages:
95+
96+
-> Debugging and observing the runtime characteristics of the chain can be challenging due to the dynamic nature of the
97+
pattern.
98+
-> If the chain is not properly configured or there are gaps in the chain, it may lead to requests being ignored or not
99+
processed correctly.
100+
101+
#### 5. Class Diagram:
102+
103+
![1702234658414](image/README/1702234658414.png)
104+
105+
#### 6. How to Run the project:
106+
107+
Run the App.java
108+
109+
Enter the input file path: Input file path with extension
110+
111+
Enter the output file path: Ouput file path with extension
112+
113+
#### 7. How to test Junit test?
114+
115+
Click on run all tests to check JUnit testcases.

image/README/1702234658414.png

837 KB
Loading

pom.xml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.cmpe202.individualproject</groupId>
8+
<artifactId>creditcard</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>creditcard</name>
13+
<url>http://www.example.com</url>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<maven.compiler.source>1.8</maven.compiler.source>
18+
<maven.compiler.target>1.8</maven.compiler.target>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>junit</groupId>
24+
<artifactId>junit</artifactId>
25+
<version>4.13</version>
26+
<scope>test</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.junit.platform</groupId>
30+
<artifactId>junit-platform-launcher</artifactId>
31+
<version>1.7.1</version>
32+
<scope>test</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.junit.jupiter</groupId>
36+
<artifactId>junit-jupiter-engine</artifactId>
37+
<version>5.7.1</version>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.junit.vintage</groupId>
42+
<artifactId>junit-vintage-engine</artifactId>
43+
<version>5.6.2</version>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.skyscreamer</groupId>
48+
<artifactId>jsonassert</artifactId>
49+
<version>1.5.0</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>com.googlecode.json-simple</groupId>
53+
<artifactId>json-simple</artifactId>
54+
<version>1.1.1</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.apache.tomcat.embed</groupId>
58+
<artifactId>tomcat-embed-core</artifactId>
59+
<version>9.0.38</version>
60+
</dependency>
61+
<dependency>
62+
<groupId>com.fasterxml.jackson.core</groupId>
63+
<artifactId>jackson-databind</artifactId>
64+
<version>2.11.2</version>
65+
</dependency>
66+
</dependencies>
67+
68+
<build>
69+
<plugins>
70+
<plugin>
71+
<groupId>org.apache.maven.plugins</groupId>
72+
<artifactId>maven-surefire-plugin</artifactId>
73+
<version>3.0.0-M5</version>
74+
</plugin>
75+
</plugins>
76+
</build>
77+
</project>

0 commit comments

Comments
 (0)