Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 25, 2007, 09:19 AM   #1
MacDonaldsd
macrumors 65816
 
MacDonaldsd's Avatar
 
Join Date: Sep 2005
Location: London , UK
Classes

How does one Class know about another class ?

Im doing a timetable application.

So every module is related to a single semester.

Therefore Semester is a class and Module is a class

Is this done through inheritance ?
MacDonaldsd is offline   0 Reply With Quote
Old Aug 25, 2007, 09:26 AM   #2
Nutter
macrumors 6502
 
Join Date: Mar 2005
Location: London, England
Just import the class definition of one class into the class implementation file of the other.
Nutter is offline   0 Reply With Quote
Old Aug 25, 2007, 09:37 AM   #3
MacDonaldsd
Thread Starter
macrumors 65816
 
MacDonaldsd's Avatar
 
Join Date: Sep 2005
Location: London , UK
Yeah but module inherits values from semester.

Such as start and end date.
MacDonaldsd is offline   0 Reply With Quote
Old Aug 25, 2007, 09:55 AM   #4
Nutter
macrumors 6502
 
Join Date: Mar 2005
Location: London, England
In that case, yes, Module could inherit from Semester. Or they could both inherit from a common abstract superclass.
Nutter is offline   0 Reply With Quote
Old Aug 25, 2007, 12:29 PM   #5
Heath
macrumors regular
 
Join Date: Aug 2005
Location: Canada
I would shy away from inheritance in this case since a module is not a semester.
'Prefer composition over inheritance' is the guiding principle here.

I would instead say that a semester contains modules.
Have instances of modules within your semester instead of having module inherit from semester.

Unless I've not understood clearly, in which case please clarify.
Heath is offline   0 Reply With Quote
Old Aug 25, 2007, 06:30 PM   #6
toddburch
macrumors 6502a
 
Join Date: Dec 2006
Location: Katy, Texas
Send a message via AIM to toddburch Send a message via MSN to toddburch
I would think a Module would be the static thing here, and it could be taught in any given Semester.

Therefore, any Semester could have a list of Modules that were taught, or, a Module could have a record of all the Semesters in which it was (or will be) taught.

One would then be an attribute of the other, and there would not be any inheritance.

start_date = module.semester().startdate() would fit the above scenario.

If any Module's start / end dates could override a Semester's start / end dates, you could do inheritance, where the Module inherited from the Semester, but now you are starting to get into some language specific implementation. In Java, Semester could be an abstract class that Module pulled in. This would get you to

start_date = module.startdate()

In C++ or Ruby though, it could be argued either way whether Module could be a subclass of Semester. I wouldn't necessarily go the other way around though.

Todd
toddburch is offline   0 Reply With Quote
Old Aug 25, 2007, 06:42 PM   #7
MacDonaldsd
Thread Starter
macrumors 65816
 
MacDonaldsd's Avatar
 
Join Date: Sep 2005
Location: London , UK
Quote:
Originally Posted by Heath View Post
I would shy away from inheritance in this case since a module is not a semester.
'Prefer composition over inheritance' is the guiding principle here.

I would instead say that a semester contains modules.
Have instances of modules within your semester instead of having module inherit from semester.

Unless I've not understood clearly, in which case please clarify.
Yeah you understand correctly. And also like toddburch said the reason I want it is so it falls within the time frame of the semester, as well as being able to seach via semester etc.
MacDonaldsd is offline   0 Reply With Quote
Old Aug 25, 2007, 07:34 PM   #8
Eraserhead
macrumors G4
 
Eraserhead's Avatar
 
Join Date: Nov 2005
Location: UK
Are you using Core Data for this application? As long as you are prepared to make it Tiger/Leopard only that would probably be the best way of managing your different object types.
__________________
Actually it does make sense. Man created god, so if we exist, He exists. - obeygiant
Eraserhead is online now   0 Reply With Quote
Old Aug 25, 2007, 10:27 PM   #9
zimv20
macrumors 601
 
zimv20's Avatar
 
Join Date: Jul 2002
Location: chicago
since we're talking design now...

i don't see any direct relationship between a Module and a Semester. just off the top of my head, i'd start with something like:

- a ClassManager would aggregate Modules

- a SemesterManager would aggregate Semesters

- a SemesterScheduler would maintain a relationship between a Semester and the Modules offered during that semester. it would also schedule when those modules occur. note that there would be some kind of helper class (like ScheduledClass) to track the multiple offerings of that Module.

- a StudentManager would aggregate Students, and also keep track of which students are active for a given Semester. it would also map students to ScheduledClasses. helper classes would resolve conflicts w/in a student's schedule, and ensure classes don't overfill. to get fancy, you could implement waitlists for scheduled classes, w/ some cool student priority logic, and allow students in when either someone drops or another of that module is offered.

- likewise, there'd be a FacultyManager to, among other things, assign faculty to ScheduledClasses.

note that plural classes are actually implemented to be singular (i.e. Student, not Students, ScheduledClass instead of ScheduledClasses).

there are many "right" ways to design this, but even more "wrong" ones. again, i'm not imagining a good design that would maintain a direct relationship between Modules and Semesters.
__________________
Oct 2011: check out my band's first album @ boxsetauthentic.com
zimv20 is offline   0 Reply With Quote
Old Aug 26, 2007, 05:22 AM   #10
MacDonaldsd
Thread Starter
macrumors 65816
 
MacDonaldsd's Avatar
 
Join Date: Sep 2005
Location: London , UK
Quote:
Originally Posted by Eraserhead View Post
Are you using Core Data for this application? As long as you are prepared to make it Tiger/Leopard only that would probably be the best way of managing your different object types.
I was going to do this, but my Cocoa/Object Orientated programming isn't amazing at the moment. All my programming ive done before is procedurally in ANSI C and PHP etc so its a few concepts il be learning at the same time.

I think core data is the way to go on this though, but im a bit scared about adding custom methods to the Classes dealt with by Core Data, and also what core data is taking care of behind he scenes and more importantly what it isn't.
MacDonaldsd is offline   0 Reply With Quote
Old Aug 26, 2007, 06:21 AM   #11
Eraserhead
macrumors G4
 
Eraserhead's Avatar
 
Join Date: Nov 2005
Location: UK
Quote:
Originally Posted by MacDonaldsd View Post
I think core data is the way to go on this though, but im a bit scared about adding custom methods to the Classes dealt with by Core Data, and also what core data is taking care of behind he scenes and more importantly what it isn't.
OK, have you gone through the tutorial on apple.com?

Personally though while creating D&D Manager with Core Data I haven't needed to use Custom Classes at all. (though I have extended NSManagedObject to allow object duplication, but that is fairly advanced.)
__________________
Actually it does make sense. Man created god, so if we exist, He exists. - obeygiant

Last edited by Eraserhead; Aug 26, 2007 at 07:06 AM.
Eraserhead is online now   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
All iPads: Using iPad for online classes rpearlberg iPad 2 Nov 23, 2013 10:59 AM
Proper way for classes to announce their existence Qaanol Mac Programming 11 Sep 5, 2013 11:28 AM
Structs and Functions or Classes and Methods? ArtOfWarfare iPhone/iPad Programming 6 Mar 21, 2013 09:27 PM
MBP or Air for Classes Adamb10 Buying Tips and Advice 1 Jun 11, 2012 02:14 PM
Functions, classes and ivars jivaro Mac Programming 6 Jun 10, 2012 04:26 PM

Forum Jump

All times are GMT -5. The time now is 10:52 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC