<?xml version="1.0" encoding="ISO-8859-1"?>

<document xmlns="http://maven.apache.org/XDOC/2.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd">

  <properties>
    <title>Class Design</title>
    <author>Checkstyle Development Team</author>
  </properties>

  <body>
    <section name="VisibilityModifier">
      <subsection name="Description">
        <p>
          Checks visibility of class members. Only static final members
          may be public; other class members must be private unless
          property <code>protectedAllowed</code> or <code>packageAllowed</code> is set.
        </p>

        <p>
          Public members are not flagged if the name matches the public
          member regular expression (contains <code>"^serialVersionUID$"</code> by default).  Note:
          Checkstyle 2 used to include <code>"^f[A-Z][a-zA-Z0-9]*$"</code> in the default
          pattern to allow CMP for EJB 1.1 with the default settings.
          With EJB 2.0 it is not longer necessary to have public access
          for persistent fields, hence the default has been changed.
        </p>

        <p>
          Rationale: Enforce encapsulation.
        </p>
      </subsection>

      <subsection name="Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
          </tr>
          <tr>
            <td>packageAllowed</td>
            <td>whether package visible members are allowed</td>
            <td><a href="property_types.html#boolean">boolean</a></td>
            <td><code>false</code></td>
          </tr>
          <tr>
            <td>protectedAllowed</td>
            <td>whether protected members are allowed</td>
            <td><a href="property_types.html#boolean">boolean</a></td>
            <td><code>false</code></td>
          </tr>
          <tr>
            <td>publicMemberPattern</td>
            <td>pattern for public members that should be ignored</td>
            <td><a href="property_types.html#regexp">regular expression</a></td>
            <td><code>^serialVersionUID$</code></td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check:
        </p>
        <source>
&lt;module name=&quot;VisibilityModifier&quot;/&gt;
        </source>

        <p>
          To configure the check so that it allows package visible members:
        </p>
        <source>
&lt;module name=&quot;VisibilityModifier&quot;&gt;
    &lt;property name=&quot;packageAllowed&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
        </source>

        <p>
          To configure the check so that it allows no public members:
        </p>
        <source>
&lt;module name=&quot;VisibilityModifier&quot;&gt;
    &lt;property name=&quot;publicMemberPattern&quot; value=&quot;^$&quot;/&gt;
&lt;/module&gt;
        </source>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="FinalClass">
      <subsection name="Description">
        <p>
          Checks that a class which has only private constructors is declared
          as final.
        </p>
      </subsection>

      <subsection name="Example">
        <p>
          To configure the check:
        </p>
        <source>
&lt;module name=&quot;FinalClass&quot;/&gt;
        </source>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="InterfaceIsType">
      <subsection name="Description">
        <p>
          Implements Bloch, Effective Java, Item 17 - Use Interfaces only to
          define types.
        </p>

        <p>
          According to Bloch, an interface should describe a <em>type</em>.
          It is therefore inappropriate to define an interface that does not
          contain any methods but only constants. The Standard class <a
          href="http://java.sun.com/j2se/1.4.1/docs/api/javax/swing/SwingConstants.html">javax.swing.SwingConstants</a>
          is an example of a class that would be flagged by this check.
        </p>

        <p>
          The check can be configured to also disallow marker interfaces like
          <code>java.io.Serializable</code>, that do not contain methods or
          constants at all.
        </p>
      </subsection>

      <subsection name="Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
          </tr>
          <tr>
            <td>allowMarkerInterfaces</td>
            <td>
              Controls whether marker interfaces like Serializable are
              allowed.
            </td>
            <td><a href="property_types.html#boolean">Boolean</a></td>
            <td><code>true</code></td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check:
        </p>
        <source>
&lt;module name=&quot;InterfaceIsType&quot;/&gt;
        </source>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="HideUtilityClassConstructor">
      <subsection name="Description">
        <p>
          Make sure that utility classes (classes that contain only static
          methods or fields in their API) do not have a public constructor.
        </p>

        <p>
          Rationale: Instantiating utility classes does not make sense.  Hence
          the constructors should either be private or (if you want to allow
          subclassing) protected. A common mistake is forgetting to hide the
          default constructor.
        </p>

        <p>
          If you make the constructor protected you may want to consider the
          following constructor implementation technique to disallow
          instantiating subclasses:
        </p>

        <source>
public class StringUtils // not final to allow subclassing
{
    protected StringUtils() {
        // prevents calls from subclass
        throw new UnsupportedOperationException();
    }

    public static int count(char c, String s) {
        // ...
    }
}
        </source>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check:
        </p>
        <source>
&lt;module name=&quot;HideUtilityClassConstructor&quot;/&gt;
        </source>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="DesignForExtension">
      <subsection name="Description">
        <p>
          Checks that classes are designed for extension.  More specifically,
          it enforces a programming style where superclasses provide empty
          "hooks" that can be implemented by subclasses.
        </p>

        <p>
          The exact rule is that nonprivate, nonstatic methods of classes that
          can be subclassed must either be
        </p>

        <ul>
          <li>abstract or</li>
          <li>final or</li>
          <li>have an empty implementation</li>
        </ul>

        <p>
          Rationale: This API design style protects superclasses against
          beeing broken by subclasses. The downside is that subclasses are
          limited in their flexibility, in particular they cannot prevent
          execution of code in the superclass, but that also means that
          subclasses cannot corrupt the state of the superclass by forgetting
          to call the super method.
        </p>
      </subsection>

      <subsection name="Properties">
        <p> None.</p>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check:
        </p>

        <source>
&lt;module name=&quot;DesignForExtension&quot;/&gt;
        </source>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="MutableException">
      <subsection name="Description">
        <p>
          Ensures that exceptions (defined as any class name conforming to
          some regular expression) are immutable. That is, have only final
          fields.
        </p>

        <p>
          The current algorithm is very simple it checks that all members of
          exception are final.  User can still mutates an exception's instance
          (e.g. Throwable has setStackTrace(StackTraceElement[] stackTrace)
          method which changes stack trace).  But, at least, all information
          provided by this exception type is unchangable.
        </p>

        <p>
          Rationale: Exception instances should represent an error
          condition. Having non final fields not only allows the state to be
          modified by accident and therefore mask the original condition but
          also allows developers to accidentally forget to initialise state
          thereby leading to code catching the exception to draw incorrect
          conclusions based on the state.
        </p>
      </subsection>

      <subsection name="Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
          </tr>
          <tr>
            <td>format</td>
            <td>pattern for name of exception class.</td>
            <td><a href="property_types.html#regexp">regular expression</a></td>
            <td><code>^.*Exception$|^.*Error$</code></td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check:
        </p>
        <source>
&lt;module name=&quot;MutableException&quot;/&gt;
        </source>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="ThrowsCount">
      <subsection name="Description">
        <p>
          Restricts throws statements to a specified count (default = 1).
        </p>

        <p>
          Rationale: Exceptions form part of a methods interface. Declaring a
          method to throw too many differently rooted exceptions makes
          exception handling onerous and leads to poor programming practices
          such as catch (Exception). This check forces developers to put
          exceptions into a heirachy such that in the simplest case, only one
          type of exception need be checked for by a caller but allows any
          sub-classes to be caught specifically if necessary.
        </p>
      </subsection>

      <subsection name="Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
          </tr>
          <tr>
            <td>max</td>
            <td>maximum allowed number of throws statments</td>
            <td><a href="property_types.html#integer">Integer</a></td>
            <td><code>1</code></td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check so that it doesn't allow more than two throws
          per method:
        </p>
        <source>
&lt;module name=&quot;ThrowsCount&quot;&gt;
    &lt;property name=&quot;max&quot; value=&quot;2&quot;/&gt;
&lt;/module&gt;
        </source>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="InnerTypeLast">
      <subsection name="Description">
        <p>
          Check nested (internal) classes/interfaces are declared at the
          bottom of the class after all method and field declarations.
        </p>
      </subsection>

      <subsection name="Examples">
        <p>
          To configure the check:
        </p>
        <source>
&lt;module name=&quot;InnerTypeLast&quot;/&gt;
        </source>
      </subsection>

      <subsection name="Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.design
        </p>
      </subsection>

      <subsection name="Parent Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>
  </body>
</document>
