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 7398161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:50:13+00:00 2026-05-29T03:50:13+00:00

I have helper class which contain different methods. I dо not want to include

  • 0

I have helper class which contain different methods. I dо not want to include it’s header file at every class that I have in my app. That approach is against DNRY I think.
Here is why I decide to create one “master” class called AppController and each class in my app to inherit it.

Here is what I do

AppController.h

#import <Foundation/Foundation.h>
#import "Helper.h"

@interface AppController : NSObject
{
  ivars...
}
 some methods ...
@end;

myClass.h

import "AppController.h"

@interface myClass : AppController
{
 ivars...
}
some methods
@end

So far, so good.
The problem rise when some class needs to inherit not NSObject, but let’s say UIViewController. This is the moment where my AppController become useless.
I know that Objective-c is not support multiple inheritance. I have read somewhere that can be done using composition, but I can’t figure out how to do that.
I will be grateful if someone gives me some examples.

  • 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-05-29T03:50:14+00:00Added an answer on May 29, 2026 at 3:50 am

    I have read somewhere that can be done using composition, but I can’t figure out how to do that. I will be grateful if someone gives me some examples.

    Yes, composition is how you do this. Your inheritance approach is wrong on several levels.

    • Your class called “AppController” is not a proper class. It captures unrelated functionality. A class should do one thing.
    • You’re forcing an awkward inheritance tree
    • You’ve called it “app controller” which is already the name of an important object in Cocoa.

    Here is how you approach this:

    • First, split up your functions and methods into related groups. You should not have one giant “utility” class. Import these functions and methods into the things that need them, not every class in the system.
    • Use categories to attach new utility functionality to existing classes (including system classes).
    • Consider functions rather than methods for many utility-like things (but still, split them up into related files, not one giant “Utility.m”).

    The vast majority of things people would normally use a “utility” dumping ground for are better solved with categories and functions in ObjC. The remainder are usually best served using delegation (but that’s another topic).

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

Sidebar

Related Questions

I have a helper class pulling a string from an XML file. That string
I have a helper class that is just a bunch of static methods and
I have a base class for many tests that has some helper methods they
I have a DB helper class which extends SQLiteOpenHelper and in onCreate, I want
I have some ASP.NET web services which all share a common helper class they
I have the following methods in an enum helper class (I have simplified it
I currently have a class file with the following enumeration: using System; namespace Helper
I have a helper class which among other things gets the current datetime. Because
I have an app that goes between many different activities. One activity, my main
I have a data mapping helper class that uses generics and reflection. Since I'm

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.