lundi 1 avril 2019

Which design pattern to use strategy or factory design?

I received a homework assignment. I am not able to decide which design pattern to use.

I have currently implemented strategy pattern. But some of my friends are implementing factory design pattern. I just need validation for the same.

This is the problem:

Suppose you are working at a new startup where you have created a collection of specialized algorithms. Interface of each algorithm is well defined in terms of input and output of the algorithm. For example:

// Class: AlgorithmFn1

public java.util.List compute(java.util.Map data)

// Class: AlgorithmFn2

public java.util.Map compute(java.util.Collection data)

and so on…

The startup plans to sell these specialized algorithms as libraries (.jar file) to its client organizations for use in their software applications. Internal implementation of these algorithms keep evolving without affecting the interfaces of algorithms.

You need to implement suitable set of classes (in Java) which can be used by the client organizations to:

Obtain new instances of concrete classes that implement the respective algorithms.

Shield the client’s code from the future changes in your implementations of the algorithms. That is, you need to design suitable classes which will exploit the object oriented programming principles for creating families of related objects without specifying the names of concrete classes of such objects.

Aucun commentaire:

Enregistrer un commentaire