A class declares, and provides the facilities to construct, manipulate, and destroy
encapsulated state, e.g., fundamental language types, library entities like vectors and deques,
and user-defined types, i.e., instances of other classes.
A class diagram shows each of the classes in one or more packages, using one of two class symbols - see Fig 2,
and shows their relationships. Classes have four kinds of relationships with other classes:
inheritance, composition, aggregation, and using.
Inheritance is shown with a triangle symbol pointing to a base class and line extending to one or
more derived classes. It represents an "is-a" relationship, as in a student is-a person.
Composition is shown with a solid diamond that is adjacent to the composer with a line reaching
to the composed class. Composition is a strong ownership relationship. The composer and composed
have the same life-time. The composed is an integral part of the composer.
Aggregation is shown with a hollow diamond that is adjacent to the aggregator with a line extending
to the aggregated class. Aggregation is a weaker ownership relationship. An aggregated part may
or may not exist throughout the lifetime of the aggregator. It is created and disposed by the
aggregating class. Aggregation may occur when a method of the aggregator creates the aggregated
instance on the native heap. It may also occur when the aggregator creates a local instance
of the aggregated in one of its methods.
Using is a non-owning relationship, shown by an arrow directed from the user to the used.
Instances of used classes are passed to the user as a reference argument in one of its methods.
These diagrams present an abstract representation of a design, in that they disclose no code,
but they do present its logical structure.
In Figure 2. we show the classes for TextFinder. TextFinder inherits the interface ITextFinder,
composes an instance of DirExplorerT<Application>, and aggregates an instance of TextSearch.
It does that by creating the instance as a local data member of its searchFile method. Application
uses TextFinder through its interface ITextFinder. Finally, DirExplorerT<Application>
composes an instance of ProcessCmdLine. We haven't shown the FileSystem classes as they are
implementation details of the DirExplorerT<Application> class.
We see that the Application class is used as
a template parameter for DirExplorerT<Application>. Its methods doDir and doFile provide
application specific processing so that DirExplorerT<Application> can be used without
modification. We've seen that Application uses the interface ITextFinder
(to access it's searchFile
method). Because ITextFinder is an interface, Application can use TextFinder without incurring a
build dependency. TextFinder uses the Application class definition to instantiate an instance
of DirExplorerT<Application>.