how to limit access to source code...

S

Sue

I have a java application which has source code for the graphical user
interface and also additional code for some calculations. I have to
give access to a few users so they can edit the calculations but I have
to limit access to the source code for the gui itself. What is the best
way to do this? I was thinking of splitting the source code into two
classes, one with the code for the graphical interface alone and the
other for the calculations part. If I do this will it be possible to
give the users the .java file for the calculations part alone with the
..class files for the gui? Should the gui class extend the calculations
class or vice versa? Also if the gui class is the one for which the
source code is not available, which class should contain the main
method? As always thank you very much for any help!
 
S

Sebastian Scheid

Sue said:
I have a java application which has source code for the graphical user
interface and also additional code for some calculations. I have to
give access to a few users so they can edit the calculations but I have
to limit access to the source code for the gui itself. What is the best
way to do this? I was thinking of splitting the source code into two
classes, one with the code for the graphical interface alone and the
other for the calculations part. If I do this will it be possible to

You are on the right way.
give the users the .java file for the calculations part alone with the
.class files for the gui? Should the gui class extend the calculations
class or vice versa? Also if the gui class is the one for which the
source code is not available, which class should contain the main
method? As always thank you very much for any help!

Reflection helps you here.

Make an interface for calculations like

-----
public interface Calc {

public void compute(someParams);

}
-----

Your application incl. gui code and main-method has to use only this
interface. Do not hardcode the classes implementing this interface (except
for a default implementation). That is the user's task. He writes a class
implementing Calc, compiles it, puts the class file to the classpath. And
now he has to provide your app with the name of the class. Perhaps via
command line, a config file or a gui dialog. Your app uses reflection to
instantiate the given class (implementing Calc) and can now use it:
 
T

Tom Dyess

Sue said:
I have a java application which has source code for the graphical user
interface and also additional code for some calculations. I have to
give access to a few users so they can edit the calculations but I have
to limit access to the source code for the gui itself. What is the best
way to do this? I was thinking of splitting the source code into two
classes, one with the code for the graphical interface alone and the
other for the calculations part. If I do this will it be possible to
give the users the .java file for the calculations part alone with the
.class files for the gui? Should the gui class extend the calculations
class or vice versa? Also if the gui class is the one for which the
source code is not available, which class should contain the main
method? As always thank you very much for any help!

Yes, you should always divorce your logic code from your GUI code whenever
possible and/or practical.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top