Re: Application Design Question
Re: Application Design Question
- Subject: Re: Application Design Question
- From: Charilaos Skiadas <email@hidden>
- Date: Tue, 17 May 2005 00:59:34 -0500
Sorry, sent it from the wrong account and it bounced back. I seem to recall Mail.app using the address you received the mail at when replying, but it doesn't do it anymore :-).
On May 16, 2005, at 10:30 PM, Jason Taylor wrote:
I am developing an application that is currently based around one major controller class called Manager. Manager controls the main window of my application, the NSSplitViews in the main window, 5 NSTableViews in the main window, as well as managing all of the addition, modification, and deletion of data. I have axillary classes that control the actual data; ie classes that allow users to add Project objects, Update objects, Contact objects, etc, but the Manager class still has to have methods that initialize a new object and add it to the main data structures. The Manager class is approaching 2000 lines and currently contains a reference to almost every part of the interface and includes the main app methods such as awakeFromNib.
How can I extend Manager so that it doesn't have to know about all parts of my application? For example, I have a sheet that allows users to add a contact. The sheet has about 20 text fields, each of which exists as a reference in Manager.h. I use Manager.h to get the values from the UI and then create a Contact object with them and add it to an array. This works fine, but every time I add a new UI element to the app, I have to add references to them in Manager.h (it has over 100 refs right now) I would like to put all of the UI references into my Contact class and have it control the sheet and do all of the creation, then just call the Manager class to add it to the Manager's data structures. How can I make Manager accessible to the rest of my application? Should I just add a sharedInstance method to it or is there some other sort of design paradigm that I should be using? Does anyone know of any example code that I can use to see how a larger scale application is created? I am relatively new to Cocoa programming and used Learning Cocoa from O'Reilly Press to start with, but it only covers small scale apps that are easy to implement. It doesn't cover modularizing your app, and I don't know of any Apple code that does either.
Any advice/pointers would be extremely appreciated.
"Cocoa Recipes for Mac OS X" by Bill Cheeseman might be just what you need. Haven't personally read it, but from what I understand it goes through a substantial application and the problems this creates.
And of course, Aaron's book is always a great place to start.
Other than that, reading other people's code can help a lot. I remember at some point in the list someone suggested some open source apps that might be good paradigms, but I couldn't find it now. Trying to understand how one of them is built, and how they have solved their problems, is probably the best way to learn object-oriented programming. (That and trying it out yourself.)
A good place to start though would be to read and understand the Cocoa API, and how it all fits together. There are a number of means of having objects communicate with each other, and overall structure, Notification centers, delegates, instantons, protocols...
And then there's bindings, which could help reduce your code size by quite a lot.
Given your description above, I would expect the program to have at least 10 classes, and I'm probably at the very low end here. Sorry, I don't have particular suggestions about how the app should be structured in your case, but I would expect the manager object to be broken up into lots of smaller controller objects, each with its area of expertise. Ask yourself, what does the manager *really* need to know about, and move everything else elsewhere. Maybe someone else can offer you more particular suggestions. Good luck!
Thanks,
Jason
<x-tad-smaller>
HTH,
Haris</x-tad-smaller>
<x-tad-smaller>Haris</x-tad-smaller>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden