处理 3 是否有 class 声明?

Does Processing 3 have class declarations?

我们的学校项目要求我们使用 Processing 3 制作游戏。在学习了该语言之后,我们的团队非常有信心我们可以使用该项目,尽管我们对所选语言有一定的保留意见。

但是,有一个主要问题我们想知道并且找不到答案。在 C++ 和许多其他语言中,当您在新文件中创建新的 class 时,您还会创建一个可以包含的头文件。 Processing 3 有类似的东西吗?我知道您可以通过添加更多选项卡来 "include" 文件,这仍然很奇怪,但无论如何。我们希望提前进行某种声明,这样我们就可以 comment/describe classes 和他们的方法,而不是强迫每个成员通过大量代码来找到合适的点。

简而言之,我们希望能够做这样的事情:

Example.pde

class Example {
  //Description
  Example();
  //Description
  void doSomething(int variable);
}

//Other team members don't have to worry past this, 
//as they have already seen the public interface

Example::Example()
{
  //Constructor
}

void Example::doSomething(int variable)
{
  //Function
}

或者我们必须总是这样:

Example.pde

class Example {

  //Description
  Example()
  {
    //Constructor
  }

  //Description
  void doSomething(int variable)
  {
    //Function
  }
}

Processing 写在 Java,所以你只能做 Java 支持的事情。 Java 不支持头文件,所以不行,你不能在 Processing 中使用头文件。

但是,听起来您真正要寻找的是 接口

interface Example {
  void doSomething(int variable);
}

class MyExample implements Example{

  public MyExample(){
    //Constructor
  }

  void doSomething(int variable){
    //Function
  }
}

有了这个,您只需要向其他团队成员展示界面,而不是class。只要他们 program to the interface,他们就不需要看到 class 实施。

有关接口的更多信息,请参见 the Processing reference