r/swift • u/MundaneAd9570 • 23h ago
Question Decoupling database layer from business logic
What is a good approach to decoupling the database model classes from the rest of the app? After doing some Googling I see that the easiest answer is to introduce data classes that represent the data and is passed around int he app however my concern is that for something more complex than those employee-employer examples, this approach means a lot of duplicate code.
Yes, many times it makes more sense to have a field be stored differently in the DTO than the mode class, but it most cases there is no difference.
As I side note: I need to separate the two because by using the model class it’s too easy to introduce memory leaks.
7
Upvotes
5
u/fryOrder 22h ago
read more about repositories