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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:39:58+00:00 2026-06-09T18:39:58+00:00

i have been asked a question about delegates, and i had some doubts about

  • 0

i have been asked a question about delegates, and i had some doubts about the right answer :

When you create your own protocol, what makes the difference between using a delegate, or just instantiating the class, and call a simple method?

I thought: with the delegate, you don’t bother instantiate a new whole class, and you can set the delegate outside the class, and just call the method with the "delegate". Is it also a good thing to use delegates to avoid the unlimited imports? as when classA imports classB, and if you instantiate the class instead of using delegates, classB also imports classA, and it causes a crash?

Are there any other good reasons when you create your own protocol/delegate?

  • 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-09T18:39:59+00:00Added an answer on June 9, 2026 at 6:39 pm

    Well, look at an example.

    Assume you have “something” that happens to display a window as part of whatever it’s doing. Without delegates or a similar setup, you’d have to be a subclass of “Window” to be able to handle window stuff, and you’d have to be a subclass of something else to handle whatever else you’re doing. So it’s either not possible, or you get into all sorts of multiple inheritance weirdness.

    Thus, you would probably end up making a subclass of whatever, and a sublcass of “Window”, and instanciate objects for both, and have them communicate somehow. Which is exactly what a delegate does, except that you have to do it over and over again for all sorts of things. Like imagine a window with 10 buttons in it, each of which needs a button sublcass that doesn’t really do all that much except for calling “ButtonXClicked” on your actual class. Again, see the “delegate” reimplemented here (yes, in Cocoa it’s not a delegate; that would be the target/action. But it’s not all that different from a delegate)?

    Thus, delegates are pretty much a convenience to connect objects that don’t really have a “kind of” relationship as implied by deriving classes.

    It also allows you to connect objects that are “created elsewhere”, like when you have something that creates an object and returns it to you: you can’t really subsitute a subclass there, but the API might still allow you to do a “setDelegate:”-like thing to connect that object to your application.

    Sometimes delegates are more appropiate, sometimes subclasses are better, and there’s probably cases where it doesn’t really matter.

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

Sidebar

Related Questions

This question may have been asked before, but I had trouble finding an answer,
I have been asked to post a new question about how to correctly sort
This question hasn't been asked yet. Some solutions probably have been proposed though to
I have been asked a question in an interview about interfaces. I am not
I've previously asked a question about an issue I have been experiencing with CSharpOptParse
I have recently had two telephone interviews where I've been asked about the differences
I know similar questions have been asked, but I'm not sure about the answers
Recently I have been asked an interview question What are the events order in
This question seems to have been asked a lot, but I haven't seen an
I know that this question must have been asked and answered a million times,

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.