Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8990035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:24:31+00:00 2026-06-15T22:24:31+00:00

Not too sure how to explain this one, but here goes… I’m building an

  • 0

Not too sure how to explain this one, but here goes…

I’m building an object structure for my data (in Objective-C) to have the following:

  • A Companies collection class
    • which contains many Company objects
      • each one of these has a Users collection class
        • which contains many User objects

The aim is to have data on the objects (i.e. companyID, companyName), and methods on the collection classes (addCompany:, deleteCompany:).

What I really want to do is to structure the classes so that I can make the following call:

[[companies getCompanyWithID:1] addUserWithName:@"Duncan"];

But to do that, I would need to put the method addUserWithName: on the companies collection class.

To me that doesn’t make sense – the methods to add/amend/delete/get users should be on the Users collection class, not on the Companies collection class.

If I put those function on their relevant collection classes, I then have to write the same statement like this:

[[companies getCompanyWithID:1].users addUserWithName:@"Duncan"];

But then it doesn’t read as nicely – because it has a nasty .users lurking in the middle.

Am I being really dumb and missing something obvious (I never went to techie school, so it’s likely I missed something fundamental which you guys all know about).

Any help, much appreciated guys. Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:24:32+00:00Added an answer on June 15, 2026 at 10:24 pm

    I may be misunderstanding your concern, but I don’t think this is an issue. Your user management methods would be on Company, not Companies, and that’s generally an acceptable pattern.

    Let’s go with the assumption that you have four classes: Companies/Company and Users/User. Now we can define a method:

    @interface Companies
    - (Company *)companyWithID:(NSUInteger)id;
    @end
    

    This says that the Companies class can get you back a Company by its ID. (Side note: in Objective-C, we rarely use the get... prefix for accessor methods – just start the method with the thing that you want, in this case company....)

    The traditional thing to do from here would be to have your Company class expose a good chunk of public API for managing users. You might do something like:

    @interface Company
    - (void)addUserWithName:(NSString *)name;
    @end
    

    In turn, the Company class will be responsible for knowing about the inner workings of the Users collection, including modifying it as necessary. With that in mind, you could write:

    @implementation Company
    - (void)addUserWithName:(NSString *)name {
        [self.users addObject:name]; // self.users is of type `Users *`
    }
    @end
    

    This way, you avoid exposing the .users to external clients of the Company class – you just pass the add... message forward.

    You could even take this strategy further and say that the Users collection class is an implementation detail and never needs to be exposed to clients of the Company class. Instead, you could provide accessors to your Users collection in terms of a more standard system collection object:

    @interface Company
    - (NSSet *)users;
    - (void)addUserWithName:(NSString *)name;
    - (void)removeUserWithName:(NSString *)name;
    // and so on...
    @end
    

    The absolute extreme of this thought process would lead you to get rid of your Users class altogether and just use system classes to manage the collection of users directly on your Company class. On one hand, this would let Xcode infer and suggest (through autocompletion) certain methods that fit this pattern well – take a look at the KVC compliance section of the Key-Value Coding Programming Guide for such methods. On the other hand, you may have more complexity that doesn’t show up in your question, so the Users class may be necessary for your use case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not too sure how to explain this, but I will try. I have
Not too sure what's going on here as this doesn't seem like standard practise
I'm not too sure what's going on here but I'm trying to echo a
Hopefully this one is not too hard to understand but I just want the
So I'm not too sure if I'm going to be able to explain this
I'm not sure how to explain this but this piece of code bellow can
Not too sure how to formulate my question and I hope that this is
Not too sure if I'm doing this right. It looks a bit more convoluted
I'm just not too sure the proper way of doing this. I basically have
I was reading the doc, but I am still not too sure. Its says

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.