java-algorithms-implementation icon indicating copy to clipboard operation
java-algorithms-implementation copied to clipboard

Report on possible code improvements applying design patterns

Open santi0ne opened this issue 1 year ago • 0 comments

Hi, due to academic issues I have reviewed your code and I have detected possible design patterns that can be implemented in order to improve the appearance of the code.

Strategy Pattern A new interface called "WithOrigin" is created which refers to methods specific to shortest path algorithms of a graph considering an initial vertex and an end. The Dijkstra and Bellman-Ford classes represent concrete classes that implement the interface described above. Each class will perform its own implementation of the methods provided by the interface. In addition, the pattern gives rise to a new class called "ShortestWay" that will represent a handler for these algorithms. It communicates directly with the client and provides it with a kind of facade (not considering the pattern) that allows to choose the algorithm of interest. image image image image

The class diagram would be as follows:

image

Decorator Pattern For this solution an interface called Node<T> was created that will be joined with the abstract class LinkedList<T> with a composition relation of multiplicity 2. The concrete classes called SinglyNode<T> and DoublyNode<T> will implement the Node<T> interface. It should be emphasized that with this solution the List<T> file, original of the analyzed code is segregated into other classes. Thus, in order to provide greater modularity. image image image The ArrayList<T> and LinkedList<T> classes, including the latter's child classes, are separated into separate files. image image image LinkedList<T> child classes. image image

The class diagram would be as follows:

image

Iterator Pattern For this solution, an extra operation is added to the IGraph interface called createIterator() that will allow choosing the type of path of interest. An Iterator interface is added with the operations used by the traversal algorithms. The concrete classes BreadthFirst and DepthFirst implement this interface. image image Iterator<T> interface. image Concrete classes that implement the interface. image image

The class diagram would be as follows:

image

santi0ne avatar Dec 27 '22 01:12 santi0ne