Reputation: 301
I have a slew of Java classes that need their objects translated to "database friendly" representation. Is it better practice to implement an interface and implement it in the 15ish classes? Or create a "workhorse" class that has a method for every single of those classes and translates it to "database friendly" values?
Upvotes: 2
Views: 43
Reputation: 726609
Implementing an interface in fifteen classes "spreads" the implementation across multiple entities, and also ties the implementation to your class hierarchy.
Localizing the implementation to a single helper class, on the other hand, lets you switch the implementation without modifying the classes or making them dependent on how you want to store them in the database. That is why a helper class would be my first preference.
Upvotes: 1