jeudi 28 novembre 2019

Is this a legit strategy design pattern usage?

I've this problem : I have to implement a list in Java and I have to make sure to guarantee the insert operations working in 2 way : when the user want the list ordered by a first parameter, I have to insert every new element to the head of the list, while when the user want the list ordered by the second parameter I have to search the correct position where to insert my new element. Since the insert operation changes its behavior according to the sorting cryterion of the list, I thought it was the case to implement the insert operation using the design pattern strategy, the Strategy interface just have the add() method and the concrete classes that implements this strategy implement differently the insertion. Is this acceptable as use of dp strategy or there's some flaws in my design process? Thanks!

Aucun commentaire:

Enregistrer un commentaire