Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Best way to model classes in objective C

Hi all! I would make an example project with some quotes that are collected in categories... There's a main view where you choose the category, then you get to a new view where random quotes of that category are displayed.

I was thinking to create a quotesCollection class that will eventually have a NSArray property with some Dictionaries inside it (A dictionary represents a quote, with Body and Author as keys). This class will have a randomQuoteWithCategory: method that will output a random quote given a certain category.

Therefore we need the quote class that will contain id, body, author and category properties.

When thinking to creating the categories for those quotes, I was tempted to overengineering and create a categoryCollection class and a category class... So I was reflecting about that: in which way would you realize the model?

Based on you experience, which advices would you give when designing classes of your projects? Which tools do you use for doing class diagrams, and which courses/books do you reccommend for gain a good sowftware design? What about Agile methodology?

Sorry for the length of the question :-)

2 Answers

I think your idea for a Quote class with id, body, author, and category is how I would approach this. I'm not sure I see the point of also having a QuotesCollection or CategoryCollection class. I can't think of a compelling reason to not use a simple array for a collection of your quotes. In creating the array, you could simply iterate over your array of quotes and add in any with matching categories.

As far as learning more about approaches to object-oriented design, I hope it's not gauche to suggest a competitor to Treehouse! Lynda.com has a great course by Simon Allardice (he's awesome) called "Foundations of Programming: Object-Oriented Design". I recommend at least looking at the first three videos, which are available for free, to see if it would suit your needs. You could then sign up for a free trial and check out the course.

Thank you very much for your answer! (late reply...)