I'm making an online game and it has a server handling smaller game server. We call it "MasterServer". This MasterServer listens to commands from both TCP and HTTP and answers to them using its own services. The thing is, the number of services is growing and I'm worried that it could reach a point where having then as simple fields would be too much.
Here's how it looks like
public class MasterServerImpl implements MasterServer { private final Logger logger; private final LevelService levelService; private final LevelStatsService levelStatsService; private final ScoreService scoreService; private final AccountService accountService; private final FriendService friendService; private final GameHostingService gameHostingService; private final CosmeticService cosmeticService; private final MessageService messageService; private final ConfigService configService; private final VersionService versionService; private final CrashReportService crashReportService; private final ShopService shopService; private final DatabaseConnection dbConnection; private final QueryProvider queryProvider; private final HttpCommandReceiver httpCommandReceiver; private final TCPCommandReceiver tcpCommandReceiver; private final ChatServer chatServer; // ... // in constructor dbConnection = new DatabaseConnection(configService.getDatabaseURL(), configService.getDatabaseUsername(), configService.getDatabasePassword()); try { dbConnection.testConnect(); } catch(SQLException ex) { throw new InvalidConfigException("Could not connect to database", ex); } queryProvider = new QueryProviderImpl(); levelService = new LevelServiceImpl(dbConnection, queryProvider, baseDir); levelStatsService = new LevelStatsServiceImpl(dbConnection, queryProvider); scoreService = new ScoreServiceImpl(dbConnection, queryProvider, baseDir); accountService = new AccountServiceImpl(dbConnection, queryProvider); friendService = new FriendServiceImpl(dbConnection, queryProvider); gameHostingService = new GameHostingServiceImpl(this, logger, port + 2); cosmeticService = new CosmeticServiceImpl(dbConnection, queryProvider); messageService = new MessageServiceImpl(dbConnection, queryProvider); versionService = new GameVersionService(versionRange, configService.getUpdateURL()); crashReportService = new CrashReportServiceImpl(baseDir); shopService = new ShopServiceImpl(dbConnection, queryProvider); httpCommandReceiver = new HttpCommandReceiver(this, logger, configService.getHttpPort()); tcpCommandReceiver = new TCPCommandReceiver(this, logger); chatServer = new ChatServerImpl(accountService, messageService, logger); For commands to work, I pass them a MasterServer instance which is an interface with specification for each services. Basically it's an interface of getter for all services. So I've got a lot of getters too in that class.
Is there a better design than simply adding stuff without caring? A lot of service could get added in the future. Each service is long enough and merging them would lose some clarity in the structure.