0

I have a bunch of properties which are common to two classes. I wanted to move those into an interface. Since these properties are both get and set, I'm not sure if I'd be allowed to set them from another class. I am implementing the interface in the class where I'd need these properties, but still I'm not being able to access these properties. My class is as follows:

public class PatchSurveyStartegy : IStrategy
{
  public IEnumerable<IEnumerable<PointBase>> ReceiverGrid { get; set; }

  public IEnumerable<IEnumerable<PointBase>> SourceGrid { get; set; }

  public SourceParameters SourceParameters { get; set;}

  public DeploymentParameters DeploymentParameters { get; set; }

  public RovParameters RovParameters { get; set; }
}

So, IStrategy is the interface where I want to move all of these properties but I'm not getting access to them in this class:

internal double DeployRemainingLines()
  {
     return StepsForGivenLines(ReceiverGrid).Sum(step => step.CalculateStepTime());
  }

I looked at these links: Interface should not have properties? and c# properties on Interface. Also, I dont want to put them in an abstract class, I want to use an interface.

Community
  • 1
  • 1
startech
  • 17
  • 1
  • 5
    I don't see where you instanciate PatchSurveyStartegy or IStrategy. Maybe you should provide that snippet. And also, at the same time, the code in IStrategy. – Mathieu Apr 05 '12 at 16:24
  • Can you give a specific compiler error or run-time exception, along with the interface declaration? – phoog Apr 05 '12 at 16:25
  • In what class is `DeployRemainingLines` defined? What error do you get? – Sergey Kalinichenko Apr 05 '12 at 16:25
  • I think I got the answer. I was making the properties, public in the interface, which was not required. Works now. Thanks! – startech Apr 05 '12 at 16:27
  • 2
    "I think I got the answer. I was making the properties, public in the interface, which was not required." Not only is it *not required*, but it is actually *prohibited*. – Sergey Kalinichenko Apr 05 '12 at 16:30
  • I'm instantiating the classes as follows: this.survey = survey as PatchStrategyForVisualizer; – startech Apr 05 '12 at 16:31
  • 'PatchStrategyForVisualizer' does not implement interface member. This is the error I'm getting :( – startech Apr 05 '12 at 16:34
  • @startech you can (and should) copy your comment as answer and mark it as accepted so others will know that your question is answered and won't need to read the entire question and all the comments to find out. – surfen Apr 05 '12 at 16:51
  • one of the bad things a developer can do is keeping the same name of the variable as name of type of variable . They will run into problems in future for this. – Dhananjay Apr 06 '12 at 03:41

0 Answers0