TheoH32 / jtf-blog

https://theoh32.github.io/jtf-blog/
MIT License
0 stars 0 forks source link

Backend Design (Inheritance, Controller, Response) #9

Open TheoH32 opened 7 months ago

TheoH32 commented 7 months ago

Inheritance

Screenshot 2023-12-13 at 12 37 38 AM

This is the main public class that I used for the 4 sorting methods to "inherit". I needed them all to follow the same structure with an array, startTime, and endTime


Screenshot 2023-12-13 at 12 40 53 AM

As you can see with my SelectionSort.java file, it inherits the main Sort.java file and its attributes. The only difference between the SelectionSort.java, InsertionSort.java, MergeSort.java, and BubbleSort.java files are the sorting algorithms that define the sorting type to which they are called

API Controller

Screenshot 2023-12-13 at 12 45 39 AM

Basically, what I did was configure each sorting algorithm to a specific endpoint. In the frontend, when the use selects the button for the algorithm they want to call, it changes the backend fetch link to the specified endpoint. The returns/responses are the same, just tailored to what specific sort the user is calling on

Response

Screenshot 2023-12-13 at 12 48 09 AM

The final aspect is the response file. You can see the setters and getters for the sorted array and sort time. These are the two things that eventually get returned into the frontend.