To provide a flexible and extendable software, it is a good OO practice
to reduce the dependencies between implementing classes. This could be
achieved by developing against abstractions which means both, abstract
classes and interfaces. By using abstractions instead of real implementation
in the application you provide some sort of contract, that could be used by
others to hook into the application with their own classes that fulfill the
contract. Except the extensibility of an application a good abstraction
reduces the risk of breaks in multiple subsystems when something was changed
in a single package. But how to get rid of all these dependencies, doing
this by hand will become an impossible job, at least for larger projects.
At this point a tool should be used to assist the development process.

The A-I chart as it is generated by PHP_Depend is based on the whitepaper
*OO Design Quality Metrics - An Analysis of Dependencies* [#ubmoodqm]_ 
published by `Robert C. Martin`__. It shows you the quality of your design
in the terms of extensibility, reusability and maintainability. All these
facts are influenced by the inter-package dependencies and the package
abstraction that PHP_Depend visualizes in form of an abstract/instability
chart.

PHP_Depend calculates the following metrics by counting classes, interfaces
and dependencies.

- **Ca - Afferent Couplings:**

  The number of other packages that depend upon classes within this package.
  This value is good indicator how changes to classes in this package would
  influence other parts of the software.
  
- **Ce - Efferent Couplings:**

  The number of other packages that classes from this package depend upon.
  This value indicates how sensitive this package is for changes to other
  packages.
  
- **I - Instability:**

  The ratio between efferent coupling (Ce) and the total package coupling
  (Ce + Ca) which is based on the following formula (Ce / (Ce + Ca)) and
  produces results in the range [0,1]. A value I=0 indicates a maximally
  stable package that depends upon nothing and I=1 indicates a total instable
  package that has no incoming dependencies but depends upon other packages.
  
- **A - Abstractness:**

  The ratio between abstract classes (ac) and the total of all classes 
  (ac + cc) that is calculated by this formula (ac / (ac + cc)) that
  results in a value in the range [0,1]. A=0 means that all classes in this
  package are non-abstract while A=1 shows a package that only consists of
  abstract classes and interfaces.

With these values we can create a chart that visualizes the relationship
between the instability (I) on the y-axis and the abstraction (A) on the
x-axis.

.. image:: /documentation/handbook/reports/media/report-a-i-chart.png
   :width:  400
   :alt:    Graphical view of PHP_Depend's metrics
   :align:  center

Because in a project not each package can achieve the optimal values of
A = 1, I = 0 or A = 0, I = 1, we draw a diagonal between the two corners.
This line is called the *Main sequence* and represents an average between
abstraction (A) and instability (I). This means that packages near this
line have a good mix between abstraction and instability. You can call
these packages *balanced*. Because it is desirable for packages to be 
close to the *Main sequence* we have a fifth metric, the package distance
(D) from this ideal.

- **D - Distance:**

  The normalized distance has a value in the range [0,1] and is calculated
  by the formula ((A + I) - 1)
  
.. [#ubmoodqm] http://www.objectmentor.com/resources/articles/oodmetrc.pdf

  *OO Design Quality Metrics - An Analysis of Dependencies*; Robert C. Martin;
  1994
  
__ http://objectmentor.com
