Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report on possible code improvements applying design patterns #196

Open
santi0ne opened this issue Dec 27, 2022 · 0 comments
Open

Report on possible code improvements applying design patterns #196

santi0ne opened this issue Dec 27, 2022 · 0 comments

Comments

@santi0ne
Copy link

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

The class diagram would be as follows:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant