mardi 17 octobre 2017

enum vs Interface design

I have a design problem where the requirement is something like this :

  1. Write a generate function that takes a parameter("TYPE")
  2. Depending on the TYPE, I need to generate a String and return it. So TYPE effectively changes the way you generate the String.

I am deliberating between two design options :

  1. Using enum : Create a enum having the TYPES. Then provide a generate method that depending on TYPE does the processing and returns a string.
  2. Using Interface : Create an interface having a function generate(). Create implementations for each TYPE, to implement the generate().

Which do you feel is better and for what reasons.

Aucun commentaire:

Enregistrer un commentaire