Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Denarius

macrumors 6502a
Original poster
Feb 5, 2008
690
0
Gironde, France
Hi Folks,

I'm just thinking through how to arrange the classes in my GUI for a programming I've been working on.

Key features are:
Reading printer data and server data from a plist.
Tab for editing printer info.
Tab for editing server info.
Writing updated printer info to Plist
Writing updated server info to Plist

The outline I had in mind was something like:

Plist class:
attribute plist with method to retrieve data from plist
Server class (inherits from Plist):
attributes serverName; MAC; IP
method to write server info to Plist.
Printer class (inherits from Plist):
Attributes printerName; printerURL; printerServer
method to write printer info to PLIST.

Does this sound a reasonable strategy or have I got the wrong end of the stick with the inheritance?

Thanks all.
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
You should probably have the plist functions all within the same class e.g. reading and writing of values.

This way you could potentially swap out the plist class with something else and any other class could still read/write the data without having to know anything about the actual data store. You could use core data or a custom XML or binary file format for example.

Cocoa programming is really designed around the Model - View - Controller concept. Basically separate out your code into each of the three roles and use methods to pass data back and forth in an agnostic way.

Your views are the UI parts (Windows). The controller is what inserts/gathers data from the views and the model would be the plist data store class.

By separating out the roles of different classes each part can be replaced or simply altered without requiring a complete rewrite of the whole app.
 

Denarius

macrumors 6502a
Original poster
Feb 5, 2008
690
0
Gironde, France
Hi Sayer,

Thanks for your reply. I think I see what you mean here, wouldn't that mean I'd have to have just one class in that case given that would pretty well leave the server and printer classes with only attributes and no methods?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.