0

Hi as a new programmer I might be violating stuff here but I have the following situation:

I have this Wafercontext architecture:

public interface IWaferContext
{
    string IN_MEDIA_TYPE { get; set; }
    string MEDIA_ID { get; set; }
    
}

public class RMTWaferContext : IWaferContext
{
    public string CONTAINER_RESULT { get; set; }
    
    public string IN_MEDIA_TYPE { get; set; }
    public string MEDIA_ID { get; set; }
    
}

public class CIMWaferContext : IWaferContext
{
    public string IN_MEDIA_TYPE { get; set; }
    public string MEDIA_ID { get; set; }
    publc string AB_DATA {get; set;}
}

I then have these interface and classes which uses it in composition:

public interface IBaseWaferContainer
{
    IWaferContext WaferContext { get; set; }
}


public  interface IWaferContainer : IBaseWaferContainer
{
   //might need to add additional things
}

public class CIMWaferContainer : IWaferContainer
{
    public CIMWaferContext WaferContext { get; set; } = new CIMWaferContext();
    public List<CIMWaferDieMeasurements> WaferMeasurementList { get; set; } = new List<CIMWaferDieMeasurements>();
}

But i get an error in the CIMWaferContainer so the code doesn't compile:

'CIMWaferContainer' does not implement interface member 'IBaseWaferContainer.WaferContext'. 'CIMWaferContainer.WaferContext' cannot implement 'IBaseWaferContainer.WaferContext' because it does not have the matching return type of 'IWaferContext'.  TDXXMLParser    

I thought it would be able to work since CIMWaferContainer inherits from IWaferContainer which is child interface to IBaseWaferContainer? Anyway to make this work?

devn00b1090
  • 97
  • 1
  • 8

1 Answers1

0

Your issue is that you're not adhering to the contract of IWaferContainer which must have a property of type IWaferContext.

Change:

public CIMWaferContext WaferContext { get; set; } = new CIMWaferContext();

To:

public IMWaferContext WaferContext { get; set; } = new CIMWaferContext();

And you're good:

public class CIMWaferContainer : IWaferContainer
{
    public IMWaferContext WaferContext { get; set; } = new CIMWaferContext();
    public List<CIMWaferDieMeasurements> WaferMeasurementList { get; set; } = new List<CIMWaferDieMeasurements>();
}
bryanbcook
  • 16,210
  • 2
  • 40
  • 69
  • So that worked. The only issue now is that when I try to use a field from CIMWaferContext it references Iwafercontext which doesn't have a definition for AB_DATA. What i mean by that is, when I use CIMWaferContainer, it only sees IWaferCOntext not CIMWaferContext – devn00b1090 Jun 10 '22 at 18:49
  • @devn00b1090, you need to typecast it back to the full type before using it, such as var cimWC = (CIMWaferContainer)WaferContext ; Then the cimWC should have/expose all you would expect of the CIMWaferContainer class structure. – DRapp Jun 10 '22 at 19:26
  • @DRapp essentially I would need to cast WaferContext to CIMWaferContext every time then? – devn00b1090 Jun 10 '22 at 19:32
  • @devn00b1090, Correct, OR... add another public property of that typecast so its always there. Something like public CIMWaferContext cimWC { get { return (CIMWaferContext)WaferContext; } }. Then, within your class, you can just refer to it via the public property and the getter will always give the proper typecasting for you. – DRapp Jun 10 '22 at 19:35
  • @DRapp So i tried this option, it does add an extra property to the class. Is this the only way to achieve this other than type casting everytime? Doesn't introducing an extra property violate some sort of rule? – devn00b1090 Jun 17 '22 at 00:59