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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:46:45+00:00 2026-06-03T05:46:45+00:00

Assume I have two base classes, Container and Gizmo . Class Container has an

  • 0

Assume I have two base classes, Container and Gizmo. Class Container has an instance variable of class Gizmo.

Now I subclass Container (call that SubContainer) and I also subclass Gizmo (SubGizmo). In some of the methods of SubContainer I need to send a message to some properties that Gizmo doesn’t have but SubGizmo does. Is there any way to override the ivar to be of class SubGizmo in SubContainer, so I can send those messages?

Right now I can make it work by casting my inherited ivar to SubGizmo every time I need to use such a property or method.

Here is why I want such a behavior: I already have a game that works, but the more modes I add, the harder it gets to maintain. If I want to change/add a method that will run on each mode; I would need to go to three different game – controller objects and make the change.

By subclassing, I wanted to keep the main game mechanics in the base classes and create a subclass for each mode. this way a change I make in a base class would reflect on each mode. However each controller and game object have new methods for different modes, and they send messages to each other. This is where my problem is arising from.

  • 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-03T05:46:46+00:00Added an answer on June 3, 2026 at 5:46 am

    just introduce type safety and conversion logic using an approach like this:

    @interface SubContainer ()
    
    - (SubGizmo *)subGizmo;
    // setter is often unnecessary
    - (void)setSubGizmo:(SubGizmo *)pSubGizmo;
    
    @end
    
    @implementation SubContainer
    
    ...
    
    - (SubGizmo *)subGizmo
    {
        Gizmo * ret = self.gizmo;
        // sanity check the type to ensure this is properly initialized,
        // or return nil if holding a Gizmo is valid in this context:
        assert([ret isKindOfClass:[SubGizmo class]]);
        return (SubGizmo *)ret;
    }
    
    - (void)setSubGizmo:(SubGizmo *)pSubGizmo
    {
        self.gizmo = pSubGizmo;
    }
    
    - (void)addWater
    {
      [self.subGizmo addWater];
    }
    
    @end
    

    however, the creeping complexity suggests more variations in types is worth consideration.

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

Sidebar

Related Questions

I have a city table that has two columns from_city to_city now lets assume
Let us assume I have two classes: class Base{}; class Derived: public Base{}; none
Suppose I have two classes a base class and an inherited class as follows:
MY base table have two colums assume col1,col2. col1 have id, col2 have many
Let's assume I have two gmdistibution models that i obtained using modeldata1=gmdistribution.fit(data1,1); modeldata2=gmdistribution.fit(data2,1); Now
Assume that I have two arrays as follow: $array1 = array(1, 3, 5); $array2
Let's say we have two objects. Furthermore, let's assume that they really have no
Assume I have a class implementing two or more COM interfaces (exactly as here
I have an abstract base class which acts as an interface. I have two
Assume I have two tables: Table MY_ENTITY ID: PK OTHER_ID: FK to table OTHER

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.