views:

43

answers:

1

I'm building a (very) simple FTP app in Cocoa, and I need to store information on the different types of servers that are supported. So, I've created a ServerType class, which stores all of the relevant information about a single type of server. I then have a ServerTypes class which is designed to manage all of the ServerType classes that are created.

My question is how to set up the relationship between the two objects. Is there a preferred method to do so?
Also, since Objective-C doesn't support non-instance classes, where should I create an instance of ServerTypes that will have to be used throughout the entire program? Or is there a better way to do that? I need it to be KVC compliant so That I can bind one of the ServerType properties to an NSPopupBox.

Sorry about the large volume of questions, I'm fairly new to Cocoa and Objective-C. If you need to see code, just ask and I'll be happy to add some. :)
SphereCat1

+1  A: 

To manage a relationship between 2 objects, you have 2 ways: composition or inheritance.

You can inherit from a class to create a subclass then you will have a is-a relationship.

If one object contains another as an instance variable then you will have a has-a relationship.

Here, I think it would be the best to use composition where the ServerTypes objects has an array of all server type objects. Objective-C supports non-instance variable (if that's what you mean), by creating static variable. Then you can use it accross the whole program

vodkhang
Awesome answer! Thanks so much. I was a little fuzzy on how the relationship types worked, but that cleared it up! :)
SphereCat1