oezg / encryption-decryption-kt

0 stars 0 forks source link

Why an enum? #1

Closed oscarnava closed 4 months ago

oscarnava commented 4 months ago

Why did you choose to implement these classes as an enum class? Consider two things:

  1. How extensible is this approach? You have two encoding algorithms right now, but imagine you had to grow it to 20, for example. You would have to have a huge enum with those 20 implementations, which would not be ideal.
  2. From the SOLID principles consider the Open-Closed Principle and the Dependency Inversion Principle. Imagine this was a library and someone had to implement a new algorithm. They would be forced to modify your library to add a new algorithm, which goes against those two principles.

How can you avoid these problems?

https://github.com/oezg/encryption-decryption-kt/blob/dc587a8b6fc924f831a849c0f8b8c0f9dfba51c5/Algorithm.kt#L3-L30

oezg commented 4 months ago

Influenced by the Funtional Programming's Discriminated Union, I chose enum because it is the closest to it. But I think you are recommending to use an interface. I will make the necessary changes. Thank you for the PR.

oezg commented 4 months ago

Can I close it now or do you think Interface is not the solution?

oscarnava commented 4 months ago

The Interface is much more adequate. 👍 Closing it.