Re: Program Structure
Re: Program Structure
- Subject: Re: Program Structure
- From: easco <email@hidden>
- Date: Wed, 29 Jun 2011 21:21:37 +0000 (GMT)
I have set out to write an address book as my first program as it means displaying data, reading it from Text Boxes and reading/writing a SQLite database. I also need to pick up button press events, fill an NSTableView and respond to click events from the table.
It works, it was difficult and I've nearly worn Google out but I'm there. What I would like advice on is the overall structure of this project as I will use it as a model for the future.
What I have is:
MainMenu.xib - what I would have called a Windows Form in VS.
JMainView - I have set this up to be the "code behind" MainMenu, it reads/writes data in the Text Boxes and handles button clicks and the selection of a record in the NSTableView, then calls functions in the other classes.
JAddressData - this is the address data class.
JAddressUpdater - reads/writes records from/to the SQLite database (it has static functions)
JDataTableSource - the data source for the NSTableView, it originally picked up the click event from the table but now just deals with the data for the table.
Is that a reasonable structure to use? If there is a web page with recommendations I am happy to look at it.
It seems reasonable for a start. You should get away from the "code behind" mentality. Microsoft Programming environments tend to work with a Model-Presenter mechanism that, in my opinion, ties puts too much application logic into the "View" portion of the application. Cocoa is geared toward "Model View Controller" and in the long run you'll find yourself fighting against the framework a whole lot less if you go that route.
As you are new to the platform please do carefully study:
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaDesignPatterns/CocoaDesignPatterns.html
The design patterns discussed in that document are pervasive.
Also, read:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html
and pay VERY close attention to following things like the naming standards and such. In my experience, folks coming from the C# world tend to want to skip over the naming conventions and continue to use a more C# (or Java) like coding style. The naming conventions in Cocoa are also pervasive and following them properly will not only help your code be readable to others, it will help you pick up the framework more quickly.
Others have mentioned that you might use Core Data instead of SQLite. Others might suggest that you plug into the built-in Address Book framework before you bother with either. I don't know if your desire to create an address book was more related to actually creating an address book application, or if that was simply a project idea you were using as an example. If you are actually trying to create an address book application I would seriously consider using the system address book framework to store your information. If, however, it was just a project idea that let you play with different things, using SQLite as a storage mechanism because you are familiar with it is OK. Core Data would be "better" but getting into Core Data is a pretty steep learning curve.
That's your biggest challenge at the moment, the learning curve of the framework. Topics that folks have been talking about, like Core Data and Cocoa Bindings, are exceedingly handy but they bring into play a lot of concepts, like Key Value Coding, and Key Value Observing that are definitely hard to wrap your mind around until you become comfortable with Objective-C and dynamic dispatching.
As you are a beginner, My advice would be to not trying to tackle those topics right away... you'll just get confused and frustrated. Spend some time with the Cocoa Design Patterns documentation, and the Objective-C manual. Write some simple applications that draw bouncing balls, or stuff information into table views. Spend some time getting familiar with Objective-C:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/OOP_ObjC/Introduction/Introduction.html#//apple_ref/doc/uid/TP40005149
Study some of the application frameworks and get a feel for Cocoa and Objective-C before you look into more advanced features of the frameworks.
During the process I had another class called JRecordManager which I have removed from the project but the output window refers to it as an unknown class. I have cleaned the project but this warning is still there. Is there something else I need to do to remove all traces of it? It isn't referred to in any of the code files now.
The unknown class is probably referenced in your xib file. You can get warnings that stem from the contents of the xib file which show up in the IDE, but the IDE is not always helpful about taking you to the source of those warnings. Are you using Xcode 3 or Xcode 4?
Scott
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden