Skip to end of metadata
Go to start of metadata

Interfaces for: (tick) READ-ONLY

DO THIS FIRST

This is the easiest option, do this first and then proceed to add functionality as required by your needs.

Design Requirement: An interface is required to publish information

Example: Need to serve up a description from a shapefile header

Details:

  • read only interface
  • internal implementation
  • thread safe

Create

 

not specified

Read

(tick)

 

Write

(error)

no setter methods provided

Thread-safe

(tick)

immutable objects are safe objects

Mixed Implementations

(tick)

 

This style of interface is used for the GeoAPI metadata package.

In all the following examples we have used Collection<CitationDate> as a return value for the getDates() methods. This is for simplicity. The tip at the end of the page shows how to use Collection<? extends CitationDate> so that the immutability of the collection is enforced at compile time rather than just at runtime.

Example Interface

Please note that the collection is specifically defined as unmodifiable in the javadocs.

Implementation Alternatives

Example Safe Implementation

Client code can use these implementations directly:

Example Safe Persistence

This example uses hibernate (which will use reflection to replace the "dates" field
bellow with a different Set implementation backed on the database.

Note the unmodifieable set is created each time.

Example Hidden Mutability

In order to "hide" mutability (ie only the application can edit against its known implementations) we need to be sure that it correctly isolates the "public" (or published) GeoAPI interface from all synchronization issues.

  • GeoAPI interface is public or published (and read-only)
  • Application implementation is private and read-write

Idea

The central difficulty of these last two examples was holding the implementation of CitationDate fixed.
We can use Java generics to enforce this change and make these implementation easier.

Changed Interface

Simplified "Hidden Mutability" Implementation

Please note the additional set methods are still not part of the interface

Labels
  • None