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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:19:29+00:00 2026-05-25T14:19:29+00:00

I don’t know if it is so complex like I say :P This is

  • 0

I don’t know if it is so complex like I say 😛

This is the case use: I have a project with a lot of targets, and all use the same common code, but I create children class to use specific things. This is the spirit of object-oriented.

I have this hierarchy in program

NSObject -> ClassA_level_1 -> ClassA_level_2
NSObject -> ClassB_level_1 -> ClassB_level_2

ClassB_level_1 have a variable ClassA_level_1 *classA so call function in level1 is no problem. The problem is that ClassB_level_1 have to call things in ClassA_level_2 (NOT level 1) in some delegates function.

If in level_2 i can call super to get things in level_1, how can I do the opposite way? There are some tricky?

  • 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-25T14:19:30+00:00Added an answer on May 25, 2026 at 2:19 pm

    When you encounter this problem, you are most likely violating Liskov’s Substitution Principle. In OOP, a square is not a rectangle.

    If you are not violating LSP, then ClassB_level_1 should still not be calling anything in ClassA_level_2. ClassB_level_2 should be where that special logic is implemented, and it should therefore know the class of its delegate, and be able to assert that the class is correct and then cast to it. That said, if you find yourself here, it’s often because of a more basic architectural problem.

    First, reconsider your problem in terms of protocols rather than classes. What functionality do you really need from this other object? Check it with a protocol and respondsToSelector: rather than by asserting some class.

    Could ClassB be a factory for ClassA so that it always creates the correct helper object? Perhaps you should reconsider this as a Class Cluster. When you find yourself creating complicated parallel hierarchies, often it’s time to pull out Design Patterns and rethink your architecture. In particular, Decorator is often useful for problems that would otherwise lead to large parallel trees.

    But if your design is correct, you just need to use respondsToSelector: to make sure your delegate responds to the method you want before calling it.

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

Sidebar

Related Questions

Don't know if this has been answered before. Have custom routes to users. If
I don't know if this has been asked before, but what i'd like to
Don't know why but I can't find a solution to this. I have 3
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this has been asked before, so point me to another question
I don't know how better to describe this. So take this example. var a
Don't overthink this - there's a very commonly used term and I ... have
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't know a whole lot about streams. Why does the first version work using
Don't know if this is the right place to ask this, but I will

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.