Java Reference
In-Depth Information
See also
F Creating a JavaFX application
Making your scripts modular
As your code grows in complexity, you will find it necessary to arrange your scripts into
well-organized modular structures. This will help your codebase to scale in size to handle
organizational complexities. This recipe addresses the facilities and practices available for
JavaFX to implement code modularization.
Getting ready
The concepts presented here deal with logical modularity of your code (physical modularity,
creating jars, is covered in Chapter 7 , Deployment and Integration ). JavaFX provides
high-level abstractions to represent code organization including packages, modules, and
classes. If you have written code in other high-level languages, you will be familiar with the
concepts presented here. For background information, see http://en.wikipedia.org/
wiki/Modular_programming .
How to do it...
To illustrate JavaFX modularization, we will create a script module and use its members to
show how modules expose their members. The full code listing for this recipe can be found
in ch02/source-code/src/module/FooBarModule.fx .
1. First, create a script file called FooModule.fx .
2. Next, add the members of the module as shown in the next listing:
public-read def size = Long.MAX_VALUE;
public var seed = Integer.MAX_VALUE;
class PrivateBar {
function genId(): Number {
new Random().nextInt(seed);
}
}
public class Bar {
def pb = PrivateBar{};
public function print(): Void {
 
Search WWH ::




Custom Search