-
Notifications
You must be signed in to change notification settings - 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.Ops
container class, nested beneath its namespace. For example, ops namedmath.add
implement theOps.Math.Add
interface. TheOps
container 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.add
are declared in thenet.imagej.ops.math.add
package. - It is OK to have subinterfaces for different sorts of ops with the same name, if needed.
- For each
Ops.Foo.Bar
interface, create anet.imagej.ops.foo.AbstractBarOp
base class, as well as one or more concrete implementing subclasses, each annotated with@Plugin
. If you have a single concrete implementing class, it will typically be namednet.imagej.ops.foo.DefaultBarOp
. See the type hierarchy of net.imagej.ops.identity for a simple example. - The reason for the
Op
suffix ofBarOp
etc. is in case the operation works with a data structure of the same name. For example, aMeanOp
might compute aMean
, aSmallestEnclosingRectangleOp
might compute aSmallestEnclosingRectangle
, and so on.
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.