-1

I tired to write Unit-Tests for a Unity3D project. There is this big issue with MonoBehaviours, making it quite hard. To solve that issue I used this tutorial to make a object construct called Humble Object.

In the tutorial has been this code (I simplified it):

public class Something : ISomething
{
  #region ISomething implementation

  void Test1() {
    // do something
  }

  #endregion

  void Test2() {
    Test1 ();
  }
}

As I get it, that should be equivalent to:

interface ISomething
{
  void Test1();
}

public class Something : ISomething
{
  public void Test1() {
    // do something
  }

  void Test2() {
    Test1 ();
  }
}

But if i write that first code and try to compile, I get this error message: (the second one does the job)

[...] The type or namespace name `ISomething' could not be found. Are you missing a using directive or an assembly reference?

2 Answers2

4

You seem to think that using #region ISomething implementation actually defines the interface.

It doesn't. #regions have no effect on the code. They are just informational.

You have to actually define the interface as in your second example (and make it at least as accessible as the implementing class, in this case public).

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
2

As I get it, that should be equivalent to:

NO, it's not at all. You have to create the interface first and that's why it's throwing the said error. Region is just code markup for better redability purpose.

Rahul
  • 76,197
  • 13
  • 71
  • 125