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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:37:36+00:00 2026-06-14T16:37:36+00:00

OK.. C# is not my forte and it’s been a while since I got

  • 0

OK.. C# is not my forte and it’s been a while since I got my head into this sort of thing and I have forgotten some things: I am struggling to get this too obey me 🙂 I am pretty sure what I want to do is possible within C# and I am pretty sure my abstracts and my interfaces are all to hell (I don’t even know how to put the interface in but I know I need one)

ok here is the scenario

//abstract parent class
abstract class ActionType
{
    /***
     * this is a parent class not meant to ever be instaciated
     */
    public abstract void action();      
}

class ActionTypeSync : ActionType
{
    public override void action()
    {
        Debug.WriteLine("doing sync");
    }
}

class ActionTypeRead : ActionType
{
    public override void action()
    {
         Debug.WriteLine("doing read");
    }
}

the following does not work

ActionType action = getActionType(1);
ActionType secondaction = getActionType(2);

[ EDIT ]

actually I was being too brief it’s THIS bit that didn’t work with error

Error Argument 1: cannot convert from ‘ActionType’ to ‘ActionTypeSync’

processThings(action);
//debug out put "doing sync"    
processThings(secondaction);
//debug out put "doing sync"   

public ActionType getActionType(int i)
{
     if (i==1) return new ActionTypeSync();
     if (i==2) return new ActionTypeRead();
}

public void processThings(ActionTypeSync action)
{
     action.action();
}

public void processThings(ActionTypeRead action)
{
     action.action();  
}

[/ EDIT ]

How best do I need to restructure this.. please understand this is a an example for sake of brevity (as best as I could) I am summarising here – so some principles are better than some “why etc etc lectures” 🙂 thank you 🙂 I don’t object to restructure in order to accommodate the polymorphic principle but I need this basic polymoprphic interface/class structure as is

  • 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-14T16:37:38+00:00Added an answer on June 14, 2026 at 4:37 pm

    Overlooking your syntactical errors, this is doing exactly what you told it to do.

    It is calling the local action() on the specific type you instantiated, it doesn’t do anything else because you haven’t told it to (i.e. at no stage are you calling base.action()).

    Edit:

    Based on your edit…. ActionTypeSync and ActionTypeRead can both be cast down to ActionType, but ActionType cannot be cast back up to either of those derived types. You can pass one of the derived objects around as an ActionType and the overridden action() method will be called, but you can’t cast it implicitly or explicitly to the derived type. To fix this just change your method signatures:

    public void processThings(ActionType action)
    {
         action.action();
    }
    

    Because of this change you will now only need one method that will deal with both derived types because you have cast it down to its base type – IOW you can get rid of the processThings(ActionTypeRead action) method.

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

Sidebar

Related Questions

CSS is not my forte so this might be something simple. I have set
I hate to sound stupid, but ASP.NET is not my forte. I have build
We have been given some code that does a URLRequest call which is really
I'll be the first to admit that PHP is not my forte and this
I've been trying to implement GLSL into my program, however given that i have
Javascript is not my forte, so excuse me if this is incredibly obvious. I'm
According to the documentation for -[UIView setNeedsLayout] : Because this method does not force
I have been tasked to create a GUI program that is to work with
I have: - an interface : IMyType - some classes implementing it : MyType1
I have a user table. I want to insert data into my user table.

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.