Advice on class structures

Discussion in 'Mac Programming' started by Denarius, Jun 2, 2008.

  1. Denarius macrumors 6502a

    Denarius

    Joined:
    Feb 5, 2008
    Location:
    Gironde, France
    #1
    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.
     
  2. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #2
    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.
     
  3. Denarius thread starter macrumors 6502a

    Denarius

    Joined:
    Feb 5, 2008
    Location:
    Gironde, France
    #3
    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?
     

Share This Page