Re: how to limit access to source code...

From: Sebastian Scheid (mynewsgroup_at_web.de)
Date: 02/11/05


Date: Fri, 11 Feb 2005 10:05:19 +0100


"Sue" <sea_099@hotmail.com> schrieb im Newsbeitrag
news:1108100716.857254.213480@f14g2000cwb.googlegroups.com...
>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:

-----
Class calcImpl = Class.forName(classNameGivenByUser);
Calc calc = (Calc) calcImpl.newInstance();
-----

Regards
Sebastian



Relevant Pages

  • how to limit access to source code...
    ... I have a java application which has source code for the graphical user ... interface and also additional code for some calculations. ... Also if the gui class is the one for which the ...
    (comp.lang.java.programmer)
  • Re: how to limit access to source code...
    ... > interface and also additional code for some calculations. ... > to limit access to the source code for the gui itself. ...
    (comp.lang.java.programmer)
  • Re: A basic question about constants. A final field that is not final?
    ... Actually, final has been removed in the source code in src.zip but it is not removed in the online javadoc at http://java.sun.com/j2se/1.5.0/docs/api/index.html, and, worse, the field of the binary version is final yet. ... I have another problem with CachedRowSetImpl. ... Do you know if I can get the source code of this implementation of CachedRowSet? ... the changes will not be committed until one of the CachedRowSet interface transaction methods is called. ...
    (comp.lang.java.help)
  • Re: C# Plugin system - same interface in two different assemblies...
    ... Yes - the source code for the interface is present twice. ... they only have to reference the assemblies they *do* use. ... Duplicating source code just makes that worse, ... If there's a bug in an SDK client helper ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: COM... is it the best model so far?
    ... prevents you from using source code reuse as this sidesteps ... each component only specifies "required interface" and "provide ... there should be a glue component or container component that are ...
    (microsoft.public.vc.atl)