A Standard Organization for Interface Documentation
This section suggests a standard organization for interface documentation (see Figure 7.1). Like all templates and organizational layouts in this book, you may wish to modify this one to remove items not relevant to your situation or to add items unique to your business. More important than which standard organization you use is the practice of using one. Use what you need to present an accurate picture of the element's externally visible interactions for the interfaces in your project.
- The identity of the interface: When an element has multiple interfaces, identify the individual interfaces to distinguish them from one another. The most common means of doing this is to name an interface. Some programming languages, such as Java, or frameworks, such as COM, even allow these names to be carried through into the implementation. In some cases, merely naming an interface is not sufficient, and the version of the interface must be specified as well. For example, in a framework with named interfaces that has evolved over time, it could be very important to know whether you mean the v1.2 or v3.0 persistence interface.
- Resources provided: The heart of an interface document is the set of resources that the element provides to its actors. Define these resources by giving their syntax, their semanticswhat happens when they're usedand any restrictions on their usage.
- Resource syntax: This is the resource's signature, which includes any information that another program will need to write a syntactically correct program that uses the resource. The signature includes the name of the resource, names and logical data types of arguments, if any, and so forth.
- Resource semantics: What is the result of invoking this resource? Semantics come in a variety of guises, including
- Assignment of values to data that the actor invoking the resource can access. The value assignment might be as simple as setting the value of a return argument or as far-reaching as updating a central database.
- Changes in the element's state brought about by using the resource. This includes exceptional conditions, such as side effects from a partially completed operation.
- Events that will be signaled or messages that will be sent as a result of using the resource.
- How other resources will behave differently in the future as the result of using this resource. For example, if you ask a resource to destroy an object, trying to access that object in the future through other resources will produce quite a different outcomean erroras a result.
- Humanly observable results. These are prevalent in embedded systems; for example, calling a program that turns on a display in a cockpit has a very observable effect: The display comes on.
In addition, the statement of semantics should make it clear whether the execution of the resource will be atomic or may be suspended or interrupted.
- Resource usage restrictions: Under what circumstances may this resource be used? Perhaps data must be initialized before it can be read, or perhaps a particular method cannot be invoked unless another is invoked first. Perhaps there is a limit on the number of actors that can interact via this resource at any instant. Perhaps there is a limit of one actor that has ownership and is able to modify the element, whereas others have only read access. Perhaps only certain resources or interfaces are accessible to certain actors to support a multilevel security scheme.
Notions of persistence or side effects can be relevant here. If the resource requires other resources to be present or makes certain other assumptions about its environment, these should be documented. Some restrictions are less prohibitive; for example, Java interfaces can list certain methods as deprecated, meaning that users should not use them, as they will likely be unsupported in future versions of the interface. Usage restrictions are often documented by defining exceptions that will be raised if the restrictions are violated.
- Locally defined data types: If any interface resources use a data type other than one provided by the underlying programming language, the architect needs to communicate the definition of that data type. If the data type is defined by another element, a reference to the definition in that element's documentation is sufficient. In any case, programmers writing elements using such a resource need to know (a) how to declare variables and constants of the data type, (b) how to write literal values in the data type, (c) what operations and comparisons may be performed on members of the data type, and (d) how to convert values of the data type into other data types, where appropriate.
- Error handling: Describe error conditions that can be raised by the resources on the interface. Because the same error condition might be raised by more than one resource, it is often convenient to simply list the error conditions associated with each resource; define them in a dictionary collected separately. This section is that dictionary. Common error-handling behavior can also be defined here.
- Any variability provided by the interface: Does the interface allow the element to be configured in some way? These configuration parameters and how they affect the semantics of the interactions in the interface must be documented. Examples of variability include capacitiessuch as of visible data structuresthat can be easily changed. Name and provide a range of values for each configuration parameter, and specify the time when its actual value is bound.
- Quality attribute characteristics of the interface: The architect needs to document what quality attribute characteristics, such as performance or reliability, the interface makes known to the element's users. This information may be in the form of constraints on implementations of elements that will realize the interface. The qualities you choose to concentrate on and make promises about will depend on the context.
- What the element requires: What the element requires may be specific, named resources provided by other elements. The documentation obligation is the same as for resources provided: syntax, semantics, and any usage restrictions. Two elements sharing this interface informationone providing it and the other requiring itmight each reference a single definition. If the element is being developed as an independent reusable component, that information needs to be fully documented. What the element requires may be expressed as something more general, such as "The presence of a process scheduler that will schedule in a priority-based fashion." Often, it is convenient to document such information as a set of assumptions that the element's designer has made about the system. In this form, they can be reviewed by experts who can confirm or repudiate the assumptions before the design has progressed too far.
- Rationale and design issues: Like rationale for the architecture or architectural views at large, the architect should also record the reasons behind the design of an element's interface. The rationale should explain the motivation behind the design, constraints and compromises, alternative designs that were considered and rejected and why, and any insight the architect has about how to change the interface in the future.
- Usage guide: Sections 2b and 7 in Figure 7.1 document an element's semantic information on a per resource basis. This sometimes falls short of what is needed. In some cases, semantics need to be reasoned about in terms of how a broad number of individual interactions interrelate. Essentially, a protocol of interaction is involved that is documented by considering multiple interactions simultaneously. These protocols could represent the complete behavior of the interaction or patterns of usage that the element designer expects to be used repeatedly. In general, if interacting with the element via its interface is complex, the interface documentation might include a static behavioral model, such as a state machine or examples of carrying out specific interactions in the form of trace-oriented scenarios.
Figure 7.1. Documentation for an interface consists of nine parts
"Exceptional" does not mean "almost never happens" or "disastrous." It is better to think of an exception as meaning "some part of the system couldn't do what it was asked to do." (Stroustrup 1997, p. 358) |