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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:03:21+00:00 2026-06-08T08:03:21+00:00

I have a class called AbstractBook , which has a property: @property(strong) AbstractPage *page;

  • 0

I have a class called AbstractBook, which has a property:

@property(strong) AbstractPage *page;

Now say I have a subclass of AbstractBook called WhiteBook and a subclass of AbstractPage called WhitePage. I want the WhiteBook class to inherit the page object, but in this class, I want it to be the specific WhitePage class instead of AbstractPage.

So, in WhiteBook, I just redeclared the property as WhitePage:

@property(strong) WhitePage *page;

However, I am getting a warning: WhitePage is incompatible with AbstractPage inherited from AbstractBook. What is the right way to implement what I’m going for?

  • 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-08T08:03:22+00:00Added an answer on June 8, 2026 at 8:03 am

    What you want to do is fundamentally impossible. Don’t forget that this:

    @property(strong) AbstractPage *page;
    

    declares a getter and a setter.

    Generally speaking (this is for OO programming generally, not just Objective-C), there is no problem with an override getter returning a subclass of the return type of the super class implementation because this does not break the API contract. In your case, an instance of WhitePage is also an AbstractPage.

    However, the setter is different. You can’t restrict the type of the parameter because your subclass must be useable anywhere where an AbstractBook is used, so code that invokes the setter on something that it thinks is an AbstractBook is entitled to pass in an instance of any AbstractPage subclass, because that is what the API says.

    I think what I would do is add a method to AbstractBook called something like

    -(bool) isLegalPage: (AbstractPage) aPage;
    

    that returns true always in the base class but true only for white pages in WhiteBook. Then I would manually implement the setter as follows:

    -(void) setPage: (AbstractPage*) aPage
    {
        if (![self isLegalPage: aPage])
        {
            // throw an exception or do other error notification
        }
        else
        {
            Do the assignment according to reference count/ARC/GC model
        }
    }
    

    Document that the setter will throw an exception if the page is not legal and that people should use the isLegalPage: method to test this.

    The alternative id to have a read only property and use different setters in the base class and subclass, or don’t have a setter at all in the base class.

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

Sidebar

Related Questions

I have a class called Property which has nothing but get -methods. All the
I have a class called Trial which has_many results. Now What I want to
I have a class called Flamethrower which naturally has its own ammunition that is
I have a class called imageResizing. It has a member, MAX_WIDTH_ORIGINAL_IMG which is defined
I have a class called class Car , which has be instantiated as the
Java Code In Java code I have class called IdentificationResult which has 3 members:
I have a class called Type: class Type { ... } Which has a
I have a class called Metadata, which is declared within the namespace A::B::C ,
I have a class called Property that I only need to display a few
I have a class called Path for which there are defined about 10 methods,

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.