Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > ObjectiveC: Logic Question

ObjectiveC: Logic Question
Thread Tools
Mac Elite
Join Date: Jul 2001
Location: Evansville, IN
Status: Offline
Reply With Quote
Apr 23, 2002, 12:14 AM
 
Ok. I am working on my first "real" Cocoa project. I am aiming for simplicity now. I wanna track a person's work in the gym. Here's what I have in the interface so far.

* Pulldown Menu w/ types of workouts (Chest Day, Leg Day, etc) [NSPopupButton]
* Dates of workouts (ie. Chest Day on 4/22/02) [NSTableView w/ 1 column]
* Table with Exercise Name, Reps, Weight, # of Sets, and general notes [NSTableView w/ 5 columns]
* A Drawer with listing of Exercises available (Bench press, Squats, etc) [Not sure whether to use NSTableView or NSView or what]


Aside from my issue with how to set up the drawer, I am having problems with trying to decide the best way to implement my classes. My method of thinking right now is to have a class named Exercise that is a subclass of NSObject w/ 5 instance variables inside (exerciseName, reps, sets, weight, notes) and then a class named Workout that is a subclass of NSObject with date, and a list of the exercises in this workout.

I am not sure how to really do the Workout class.

Any help is appreciated.
Justin Williams
Chicks Really Dig Me
AIM - iTikki [NEW AND IMPROVED!]
http://www.tikkirulz.com
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Apr 23, 2002, 02:51 AM
 
I'm not sure exactly where you need help. It sounds like you already know what you want to do. An NSCalendarDate and an NSMutableArray of Exercises and you should be good to go. And I'm not really clear on how you're planning on hooking things together, but it sounds like it would make sense to make the current Workout the data source for your NSTableView too.

And as for the list of exercises--unless you have some particular quirk to the list or something, a one-column NSTableView sounds like it should be exactly what you're looking for.

I'm not sure exactly what context this will be used in, but one other thing that immediately occurs to me is that you might also want a Person class to store all of the Workouts a person has done. (Then again, if you're anticipating only a single-user system, you may as well just write it straight to a file.)

[EDIT: Accidentally wrote "delegate" instead of "data source."]

[ 04-23-2002: Message edited by: Chuckit ]
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Apr 23, 2002, 08:00 AM
 
A weigh-in variable in the person class would be good to

kman
     
Mac Elite
Join Date: Jul 2001
Location: Evansville, IN
Status: Offline
Reply With Quote
Apr 23, 2002, 09:56 AM
 
Originally posted by Chuckit:
<STRONG>I'm not sure exactly where you need help. It sounds like you already know what you want to do. An NSCalendarDate and an NSMutableArray of Exercises and you should be good to go. And I'm not really clear on how you're planning on hooking things together, but it sounds like it would make sense to make the current Workout the delegate for your NSTableView too.</STRONG>
I am not sure how I should hook up the Exercise class and Workout class. Do I even need to do it with two classes? This is my first real dive into Object-Oriented programming, so I am just trying to reassure myself.

I'm not sure exactly what context this will be used in, but one other thing that immediately occurs to me is that you might also want a Person class to store all of the Workouts a person has done. (Then again, if you're anticipating only a single-user system, you may as well just write it straight to a file.)
Right now, I am just building this for myself to see what I can accomplish, so multi-user isn't really an issue.
Justin Williams
Chicks Really Dig Me
AIM - iTikki [NEW AND IMPROVED!]
http://www.tikkirulz.com
     
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Apr 23, 2002, 01:10 PM
 
Just stick with the view-controller-model idea of design. You have the models down (Excercise and Workout) and the views are taken care of more or less by IB. You just need a Controller class to take care of the middle stuff--accessing the models and displaying on the interface.


You will want Workout to have an NSArray (or NSMutableArray) containing references to the instances of Excercise that correspond to each excercise you do (curls, hip press, etc) in that particular instance of Workout (chest, legs, whatever).

You might want your controller to keep a master array containing all of the possible instances of Excercise so that you can access them to edit the number of reps, etc. You will probably want this to be a mutable array so you can add and remove excercises. The controller should also have an array containing references to the instances of Workout. Your encoding will be pretty easy. The controller should encode the array of all possible excercises and the array of workouts. Workouts should then encode the array of excercises in that workout along with the instance variables of that workout. Excercise should encode all of its instance variables.

Mind you, I'm a newbie to Cocoa as well, but that's my two cents.

kman

[ 04-23-2002: Message edited by: kman42 ]
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Apr 23, 2002, 02:24 PM
 
Originally posted by Justin W. Williams:
<STRONG>
I am not sure how I should hook up the Exercise class and Workout class. Do I even need to do it with two classes? This is my first real dive into Object-Oriented programming, so I am just trying to reassure myself.
</STRONG>
Well, like you said, a Workout is basically a date and a list of Exercises on that date, right? That tells you how to hook them up. For a date, you've got NSCalendarDate. For a list that you're going to be adding things to, the easiest way to do it is an NSMutableArray. So then, everytime the user creates an Exercise, you add it to the appropriate Workout's NSMutableArray of Excercises. That sounds like what you're looking for to me.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:52 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2