Student ID: 017426955
The primary challenge I aim to address is the validation of credit cards. This involves identifying the card type (e.g., Mastercard, Visa) by examining the card number and handling the relevant objects accordingly.
The secondary challenge involves deciding on suitable design patterns and accommodating future additions of credit classes for different card types.
Design Patterns Implemented: Chain of Responsibility, Strategy
The Strategy Design Pattern allows dynamic behavior changes in the application at runtime. It supports multiple file formats by creating objects and strategies specific to each, adapting the application's behavior accordingly.
I employed the Strategy Design Pattern to handle various file formats. Three interfaces - Reader, Writer, and CreditCardHandler - were designed to manage different aspects of file processing and credit card handling.
Reader: Defines a common contract for classes that read input files, including a readFile method for reading based on the file type. CreditCardHandler: Establishes a common structure for classes responsible for checking credit card types, with a checkCreditType method for determining the card category. Writer: Provides a structure for classes responsible for writing data to different file formats, featuring a writeToFile method for handling the output format. This pattern enables runtime behavior swapping, adhering to the Open/Closed principle, and facilitates the addition of new strategies without affecting existing code.
The Chain of Responsibility pattern handles requests by passing them through a chain of handlers. Each handler decides whether to process the request or pass it along the chain.
After parsing XML, JSON, or CSV files, validation is needed to determine the credit card type. The Chain of Responsibility pattern validates the file against different credit card handlers, starting with the MasterCard handler and passing it along the chain as needed.
A main credit card handler acts as a mediator, receiving the file and passing it to individual credit card handlers for validation. This approach centralizes and organizes the validation process.
Chain of Responsibility \n Advantages: Decouples the sender from recipients. Clients interact with the chain through direct method calls. Easily modify or adjust the chain order. Disadvantages: Debugging and observing runtime characteristics can be challenging. Improper chain configuration may lead to ignored or incorrectly processed requests. Strategy Design Pattern: Advantages: Flexibility in adding new strategies without impacting existing code. Promotes code reusability. Disadvantages: Users need to be aware of multiple strategies. Large numbers of objects may become cumbersome.
Run App.java
Enter input file path: [Input file path with extension]
Enter output file path: [Output file path with extension]
How to Test Junit: Click on "run all tests" to check JUnit test cases.