1

I have heard, that each class should always just be responsible for a single purpose, otherwise you should rethink your design.

So here are the concerned classes:

  • WebSocketController: provides basic interaction with a WebSocketServer, is observable (in SWIFT through events and in Java through a modfied observer pattern)
  • RaceDataFacade: provides methods like registerForRaceEventsAtServer or registerForMeasurementsAtServer
  • JsonParser: responsible for parsing the incoming data into easy-to-use entities.

The thing now is that I want to have the whole JSON logic outsourced (to be able to parse other files from the server eventually).

So I have implemented a method parseEntities inside my JsonParser:

  1. Determine which data has been received from the server (RaceEvents or Measurements)
  2. Parse a collection
  3. Return a collection of type Entity (mutual superclass)

In RaceDataFacade determin whether the collection is of type RaceEvent or Measurement and call onRaceEventsUpdated respectively onMeasurementsUpdated.

Especially in SWIFT the type conversions are a bit difficult to do, yet finally work. Is this a good design, or should I change it somehow?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.