0

Our school project has us make a game using Processing 3. After some studying with the language, our team is pretty confident we can work with the project, though we do have certain reservations of the chosen language.

However, there is one major question we are wondering and could not find an answer. In C++ and many others, when you create a new class in a new file you also create a header file you can include. Does Processing 3 have something similar? I know you can "include" files by adding more tabs, which is still weird but whatever. We would like to have some sort of declarations in advance so we can comment/describe classes and their methods, rather than force each member go through lots of code to find the proper point.

In short, we want to be able to do something like this:

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
}

Or do we have to always to like this:

Example.pde

class Example {

  //Description
  Example()
  {
    //Constructor
  }

  //Description
  void doSomething(int variable)
  {
    //Function
  }
}
Mandemon
  • 372
  • 3
  • 22

1 Answers1

1

Processing is written in Java, so you can only do things that Java supports. Java does not support header files, so no, you can't use header files in Processing.

However, it sounds like what you're really looking for is an interface.

interface Example {
  void doSomething(int variable);
}

class MyExample implements Example{

  public MyExample(){
    //Constructor
  }

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

With this, you would only need to show other team members the interface, not the class. As long as they program to the interface, they don't need to ever see the class implementation.

More info on interfaces can be found in the Processing reference.

Community
  • 1
  • 1
Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
  • Hmm, I see. Perhaps we need to hold extra meeting to adjust our coding conventions so that all class files FIRST describe the interface, THEN implement the class. That way we could have our "headers", assuming I understood your description correctly. – Mandemon Feb 03 '16 at 19:17
  • @Mandemon Honestly, it sounds like you're overthinking it. If this is just for a school project, why do you need an interface or header files at all? Can't you just tell your teammates what the functions will be? Can't they just see for themselves? What problem are you trying to solve? – Kevin Workman Feb 03 '16 at 19:19
  • Were given "simple" tasks of taking Bomberman and BoulderDash and making a game out of the two. From scratch. So we need to split up the work, but we also want to quickly share current work being done. Plus, we are all more used to working with C++ so we are used to headers. – Mandemon Feb 03 '16 at 19:36
  • @Mandemon Fair enough. But that's part of the fun of working in a new language- learning how it's different from languages you've already used. I personally think you're overthinking it and should just use simple classes, but if you really want some kind of abstraction to work from, interfaces are what you're looking for. Good luck. – Kevin Workman Feb 03 '16 at 20:09