Shop OBEX P1 Docs P2 Docs Learn Events
Class limits for Javelin. — Parallax Forums

Class limits for Javelin.

DerryDerry Posts: 8
edited 2005-11-29 16:36 in General Discussion
Peter, you mentioned recently a limit of 64 methods in a class. Does this number include all methods of superclasses or just the individual class being defined? Do you (or anyone else) know what other limits there might be?

I've built a solar thermal controller with a MODBUS/ASCII interface. I wrote a simple language for defining the MODBUS variables, and a generator to create a Java class containing the various constants, variables and methods needed to work with those variables. The problem is that it is BIG. This controller has about 85 parameters, sensor inputs and relay outputs that are represented in MODBUS variables. That means the generated class contains 85 (plus a few) scalar variables, 85 instances of a class that describes the MODBUS variables, 85 (plus a few) "set" methods, a method containing a switch statement with 85 cases, a few hundred static final constants... You get the idea. I think there are steps I can take to reduce these numbers or split up the file, but I would like to do it by some means other than trial and error. Thanks.

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-29 03:17
    There are several limits per class.

    methods < 64

    strings < 128

    statics < 128 (not static final I believe)

    Wether those limits are fixed I don't know. They could depend on total code size.

    When you extend a class the superclass and extended class methods are summed.

    I guess that also applies to strings and statics.

    Usually it compiles ok even if you cross the limits, but when you try to program

    an error message appears.

    I would say if your program compiles and programs ok just keep it until such message

    appears. On the other hand, 85 methods for a class is alot. I am sure you define

    several logic blocks in your class that could be placed in a seperate class.·That usually

    also clarifies your program.

    regards peter
  • DerryDerry Posts: 8
    edited 2005-11-29 16:29
    Thanks, Peter, that's helpful. It compiles but I haven't tried loading it yet! Actually the 85 methods are not part of a complex mess of code, they are setter methods for the MODBUS parameters, so they are all of the same form: public int setXxx(boolean value) or public int setYyy(int value) and one line of code. It's more convenient for me to have them all in one place, but I can split them up if need be.

    Derry
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-29 16:36
    I don't know your code, but if xx and yy represent some register and your one line of code

    are nearly identical, perhaps you could simplify that to

    public int setX(int xx, boolean value)

    public int setY(int yy, int value)

    and define your xx and yy as constants.

    regards peter
Sign In or Register to comment.