Java : Decorator & Chain of Responsibility
Java : Decorator & Chain of Responsibility
In this assignment, I was tasked with combining the Decorator Pattern with the chain of responsibility pattern (COR) to create a program that converts length.
If you are unfamiliar with these terms and ideas, you can simply relate them to real life events as their name implies what they are supposed to do.
Decorator: similar to a pizza being decorated with toppings, or a coffee being decorated with extra sugar / cream, this implies that a single object created will be passed to other handlers (classes) that will deal with putting on their own changes to the current object.
Chain Of Responsibility (COR): this goes hand in hand with a decorator pattern. The COR passes off an object for other classes to work with. For instance, if you are working in a resturaunt, the short order cooks are not responsible for taking out the food and ensuring the customers get the food, they only need to focus on cooking it. They pass off the responsibility to other waiters in the restaurant. This combines the use of a GUI created using the Java Swing library alongside object oriented pattern designs to create a program that requests kilometers and converts it to respective measurements of : MILE, YARD, FOOTTo run this assignment, download the source files located at the bottom of this page.
After downloading the files, extract the java class files located in the src folder into a package in your eclipse or whichever IDE you are using, and navigate to the Converter.java file. This java class file contains the code to run the overall program along with extensive comments that helps with understanding what the code is doing. Please note there are various print statements for my own use during debugging, and you are more than welcome to remove them if it helps out with clarity.
Below is a small demo of me downloading, installing, running, and explaining the program.