I've been developing an application similar to Whatsapp (with its special features of course) and am now at the point where I think I should refactor all the existing code to make it conform with the MVC design pattern (because of too much glue code).
If I'll break my application to some simple stuff, we'll have:
- First Message:
- ID
- Any Unread Message
- Source User
- Target User
- Normal Message:
- ID
- First Message (weak reference)
- Received State (Got to server/Got to client/Read by client)
- Am i owner of message (am I source)
- Date
- User:
- ID
- Phone Number
- Profile Image Link
Note the "Any Unread Message" should be ON if there are any messages the user didn't read. just an optimization from the server.
I've never really worked with the MVC design pattern properly so I would like to make sure that my plans are correct or perhaps there are additional/other stuff I should do.
I was thinking about:
- Model:
- Create a Core-Data xcdatamodel file which will hold the above entities
- Use the library mogenerator to generate entity files from the core-data model
- Create Data-Models for each operation. for example: Register Data-Model which will handle all the registration api with the server; Message Data-Model which will handle sending a new message and retrieving new messages; etc. All of these will be singleton.
- View:
- all the views of whatsapp like outer UITableViewController (to display unique users) and inner UITableViewController (to display messages from a specific user).
- Controller:
- uses some of the above data models to fetch new data explicitly
I'm thinking to just give an API from the model to the controller which it can use it explicitly but that doesn't use the notifications or Key-Value-Observing designs.
I haven't found any online tutorial or document that explains what's the better thing to do.
Any suggestions?
Aucun commentaire:
Enregistrer un commentaire