JMRI: Introduction to JMRI Library StructureBecause we expect to have different interfaces in the
jmrixpackage, the JMRI tools don't directly create the interface objects they need. Rather, they ask for instances of interfaces. For interfaces in the
jmripackage, which might be implemented by lots of different layout types,
jmri.InstanceManagersatisfies these requests.
More information on how things (e.g. objects representing items on the layout) are named is available on a separate page.
- Contains interfaces and base class implementations for
the common JMRI objects. This is the basic interface to the
overall JMRI library and its capabilities.
Code in the jmri package should depend on no other JMRI code, though it may depend on externals (log4j, etc.)
- Separate from the jmri package tree, this contains application classes and base classes that can use jmri, jmrit, and jmrix classes, along with anything else. By having this here, we break the dependency between jmrix and jmrit classes (somebody has to create the general and system-specific tool objects for an application; that dependency is from the apps package)
- Contains commonly useful tools and
It can depend on jmri.* and externals. It must not depend on jmrix.*
- Contains code that is specific to a particular
external system. This includes
implementations of jmri interfaces that are specific to a
system, plus system-specific tools (in the long run, those
could certainly be separated).
jmrix can depend on jmri and externals, but not jmrit.
- General service classes that are _not_ user level tools.
- Abstract and default implementations of the various JMRI type managers, e.g. the concrete classes from the InstanceManager. It's a historical accident that these have a package of their own, rather than being rolled into jmri.implementations.
- Abstract and default implementations of the jmri objects; no system specific or Swing code allowed here. These are in a separate package, rather than in jmri itself, to make the jmri package simpler to understand for people who just want to use the library.
Extensive use of Factory pattern via objects we call "Manager" objects.
Example: a TurnoutTurnouts involve:
- Turnout - the basic interface. This is what you should expect to deal with when writing your layout automation code; its what you get when you make a request from the TurnoutManager, etc.
- AbstractTurnout - provided for convenience when implementing the Turnout interface for specific hardware, this provides the basic implementation.
- LnTurnout - a specific implementation for LocoNet-connected turnouts.
To get a specific Turnout instance that represents something on the layout, you make a request of a TurnoutManager. This is also an interface, with a similar implementation pattern.