Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-c class design/organization

I've created my first iPhone app that presents audio tracks of a similar genre in a tableview. The user can play audio tracks using ipod-like controls which streams mp3.

All of my code is in two main classes: RootViewController and CustomCell.

My RootViewControllerClass is massive. I'm assuming it is poor design to stuff almost all of my code in one class?

Initially, I thought it made sense because I only have one View Controller. To practice better coding conventions, I'd like to split up my RootViewController class into smaller, specific classes (assuming this is the correct practice?).

Here are the components of RootViewController that I plan to separate out into individual classes:

  • DataSource - pulls data from server; modifies and organizes the data for the tableView
  • TopChartsView - includes buttons in a view to modify the audio tracks(dataSource) by top rated weekly/monthly/all-time
  • GenreChange - includes buttons in a view to filter the dataSource by genre
  • AudioPlayerControls - includes buttons in a view that are similar to iPod controls

Am I organizing my classes correctly? It seems to make sense that I organize my classes by function. However, I'm having difficulty grasping how classes should interact with each other in an ideal design.

Do I use protocols and delegation to link my classes together?

like image 460
mnort9 Avatar asked Jan 26 '26 12:01

mnort9


1 Answers

Designing iOS apps is mostly about the MVC design pattern, which means that you seperate your model, view and controller. In your case I would put the DataSource logic in a seperate file or files (it's your model). This also makes it easier to reuse the same logic in another view controller in a later point. Maybe you can also subclass your UITableView if lots of code resides there.

Protocols and delegates are a great way to connect your classes and they are very frequently used in a good design. Since you don't have many viewcontrollers in your application (as far as I see), there are not very much opportunities to use them, please correct me if I'm wrong ;)

like image 105
Devos50 Avatar answered Jan 28 '26 03:01

Devos50