Implement Design Patterns to Get Better Structure #477
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement Design Patterns to Get Better Structure
1. Singleton:
Singleton design pattern is defined as single class has single responsibility. This pattern makes use of a single class that is in responsible of producing an object while assuring that only one is produced. This class has an object-access function that may be used without initially constructing the class.
Roles – Singleton can be applied on Utils.java class
(Utils.java, private Utils() and static Utils getInstance()) can be implemented.
Location: src/main/java/technology/tabula/Utils.java
src/main/java/technology/tabula/Page.java
src/main/java/technology/tabula/TextStripper.java
I have implemented this design pattern for part 2 please check out the UML diagram provided there for better understanding.
Implemented by these steps:
So here for tabula-java project there is one class called Utils which contains all the utilities in the program. We can implement the singleton for this class by
2. Factory Design Pattern:
The Factory pattern to create objects without revealing the creation code to the client, and we refer to newly produced objects using a common interface. This type of design pattern is characterised as a creational pattern since it provides one of the best methods to build an object.
Roles – CommandLineApp and TestWriters may have factory pattern for writers by implementing from the Writer.java.
(CommandLineApp.java, public void Writetabels(),
Calling two different writers CSVWriter and JSONWriter)) can be used by the Factory Design pattern.
I will implement class FactoryWriter.java for it.
I have implemented this design pattern for part 2 please check out the UML diagram provided there for better understanding.
Location:
src/main/java/technology/tabula/writers/Writer.java
src/main/java/technology/tabula/writers/JSONWriter.java
src/main/java/technology/tabula/writers/JSONWriter.java
src//main/java/technology/tabula/CommandLineApp.java
Can be implemented by these steps:
[FactoryWriter.getInstance(“Which ever functionality”)]
3. Prototype Design Pattern:
By implementing a prototype interface for TabulaInterface, then we can create a clone of the current object. Then this prototype will be used in the place of creating new object which will help creating the clone of that object. A prototype is a cloneable object. When the objects contain dozens of fields and hundreds of possible configurations, cloning them may be a better alternative than subclassing.
Roles – Prototype can be applied on Multiple places for example Line.java and TextChunk.java
(Line.java, TextChunk.java) can be used by the prototyping it.
Location:
src/main/java/technology/tabula/Line.java
src/main/java/technology/tabula/TextChunk.java
Implemented by these steps:
Thank you for giving me the opportunity to contribute to this project I would be glad if you accept this pull request. Please contact me if you have any questions or suggestions or any additions to this pull request. Looking forward to hearing back.