-
Couldn't load subscription status.
- Fork 42
Naming
Each op has a name, which is not necessarily unique. This allows multiple "overloaded" ops with different combinations of parameter types, similar to the method overloading feature of Java and other programming languages.
Ops may optionally have a namespace. This is similar to packages in Java and similar features in other languages. The namespace is expressed as a prefix; such ops are referenced by their namespace, followed by a dot, followed by the op name. Ops without a namespace belong to the "global" namespace, with no prefix or dot. Two ops with the same name but different namespaces do not "overload" or "override" one other.
The naming convention for both namespaces and op names is to use an alphameric string, in lower camel case.
We use the following guidelines:
- Each kind of operation has an associated interface in the
net.imagej.ops.Opscontainer class, nested beneath its namespace. For example, ops namedmath.addimplement theOps.Math.Addinterface. TheOpscontainer class is autogenerated from a Velocity template; see Ops.list and Ops.vm. - Each kind of operation lives in an associated package matching its namespace and op name. For example, ops named
math.addare declared in thenet.imagej.ops.math.addpackage. - It is OK to have subinterfaces for different sorts of ops with the same name, if needed.
- For each
Ops.Foo.Barinterface:- Optionally create a
net.imagej.ops.foo.BarOpinterface which extends it. Typical reasons for having this additional interface include: to compose with other interfaces, to add generic parameters, and/or to add needed API methods. The reason for theOpsuffix is to avoid naming confusion—especially if the operations work with a data structure of the same name. E.g., aMeanOpmight compute aMean, aSmallestEnclosingRectangleOpmight compute aSmallestEnclosingRectangle, and so on. - Optionally, create a
net.imagej.ops.foo.AbstractBarbase class. - Create one or more concrete implementing subclasses, each annotated with
@Plugin. Name your concrete implementing classes in a way that will differentiate them, typically by referencing their input type arguments somehow—e.g.,CorrelateFFTImgandCorrelateFFTRAI. If you have a single concrete implementing class, it will typically be namednet.imagej.ops.foo.DefaultBar. See the type hierarchy of net.imagej.ops.identity for a simple example.
- Optionally create a
The OpService provides built-in type-safe methods corresponding to all ops available in the core Ops library. These methods are consistent with the patterns discussed above: global ops have methods directly in OpService, while the ops of a particular namespace are accessible via their Namespace class, which is accessible from the OpService. For example, to call a math.add op, you would write ops.math().add(...), where ops is a reference to the OpService instance.