1

Ok, this takes a bit of setup first.

public interface IPolicyObjectAdapter
{
    PolicyImage GetPolicyImage(BridgePolicy policy);
}

public class BridgePolicyAdapter : IPolicyObjectAdapter
{
    protected virtual PolicyImage GetPolicyImage(BridgePolicy policy)
    {
         AddPolicyInformation(policy);
    }

    protected virtual void AddPolicyInformation(BridgePolicy policy)
    {
       //does stuff
    }
}


public class HSPolicyAdapter : BridgePolicyAdapter, IPolicyObjectAdapter
{
     protected override void AddPolicyInformation(BridgePolicy policy)
     {
          base.AddPolicyInformation(policy);
          //does more stuff
     }
}

When I execute the following code, I expect the code to enter into the HSPolicyAdapter's AddPolicyInformation method. But it never does. It just goes straight into the BridgePolicyAdapters AddPolicyInformation method.

IPolicyObjectAdapter Adapter = null;
Adapter = new HSPolicyAdapter();
PolicyImage image = Adapter.GetPolicyImage(policy);

I am sure I am missing something so obvious it will hurt, but my brain isnt working right now. What am I missing?

6
  • 3
    You are calling GetDiamondPolicyImage but your source code shows GetPolicyImage. Please could you clarify by putting the correct code please? Commented Nov 15, 2012 at 2:16
  • 1
    In addition, you call base.AddPolyInformation(polyicy, Img). What's with the Img parameter? I think you'll need to post an actual working code set for us to test. On the face of it, it seems that you have the overall concept right, but likely there's just a small oversight but we can't answer it without more accurate information from you. Commented Nov 15, 2012 at 2:42
  • Also, the first thing you do is call base.AddPolicty..., so if you put a break-point there, it should hit. Commented Nov 15, 2012 at 3:16
  • Also check this: GetPolicyImage returns PolicyImage but AddPolicyInformation doesn't return anything. Commented Nov 15, 2012 at 5:06
  • @JoshGough, I did place a breakpoint at the call to base.AddPolicyInformation in the HSPolicyAdapter and it was never triggered. Commented Nov 15, 2012 at 7:02

1 Answer 1

1

I cobbled together this interpretation and it worked fine for me:

public class BridgePolicy
{
    public string Name { get; set; }
}

public class PolicyImage
{
    public string Name { get; set; }
}

public interface IPolicyObjectAdapter
{
    PolicyImage GetPolicyImage(BridgePolicy policy);
}

public class BridgePolicyAdapter : IPolicyObjectAdapter
{

    protected virtual void AddPolicyInformation(BridgePolicy policy)
    {
        //does stuff
    }


    public virtual PolicyImage GetPolicyImage(BridgePolicy policy)
    {
        AddPolicyInformation(policy);

        return null;
    }
}


public class HSPolicyAdapter : BridgePolicyAdapter, IPolicyObjectAdapter
{
    protected override void AddPolicyInformation(BridgePolicy policy)
    {
        base.AddPolicyInformation(policy);
        //does more stuff
    }
}


class Program
{
    static void Main(string[] args)
    {
        BridgePolicy p = new BridgePolicy();
        IPolicyObjectAdapter Adapter = null;
        Adapter = new HSPolicyAdapter();
        PolicyImage image = Adapter.GetPolicyImage(p);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.