I have a very large class called DatabaseService that fetches, caches, and updates various streams of data. I'm now attempting to separate each logical block of data into individual files to make it easier to manage. However, I'd like to keep all the methods and streams accessible by providing just the one DatabaseService file.
My DatabaseService has these various groups of methods and streams of data that I'm separating into individual files:
- Users
- Feed
- Stories
- Comments
The difficulty is that each group of data depends on streams from the other groups of data. For example, comments require the stories feed, and so on: Comments < stories < feed < user
My first iteration looked like this:
class DatabaseService {
// Here, i expose the various streams from each subclass
Stream<User> userStream = UserService.instance.userStream;
Stream<Feed> feedStream = FeedService.instance.feedStream;
Stream<Stories> storiesStream = StoriesService.instance.storiesStream;
Stream<Comments> commentsStream = CommentsService.instance.commentsStream;
...
DatabaseService() {
}
Things quickly become messy when I have to push data to each sub-service and expose multiple methods, or if i need to access methods from one another.
I've looked into using mixins, which look great, but I can't access streams from one sub-class to another.
Is there a better way to do this?