|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Orthogonality is a concept often used to describe modular and maintainable software, but it's more easily understood by way of a case study. In this article, Jens Dietrich demystifies orthogonality and some related design principles by demonstrating their use in the popular Log4j utility library. He also discusses how Log4j violates orthogonality in a couple of instances and discusses possible workarounds to the issues raised.
The concept of orthogonality is based on the Greek word orthogōnios, meaning "right-angled." It is often used to express the independence between different dimensions. When an object moves along the x-axis in a three-dimensional space, its y and z coordinates don't change. Change in one dimension does not cause change in another dimension, which means that one dimension cannot cause side-effects for others.
This explains why the concept of orthogonality is often used to describe modular and maintainable software design: thinking about systems as points in a multi-dimensional space (spawned by independent, orthogonal dimensions) helps software developers to ensure that our changes to one aspect of system will not have side-effects for another.
It happens that Log4j, a popular open source logging package for Java, is a good example of a modular design based on orthogonality.
Logging is just a fancier version of the System.out.println() statement, and Log4j is a utility package that abstracts the mechanics of logging on the Java platform. Among other things,
Log4j features allow developers to do the following:
While Log4j does have other features, I will focus on these three dimensions of its functionality in order to explore the concept and benefits of orthogonality. Note that my discussion is based on Log4j version 1.2.17.
Get an overview of Log4j and learn how to write your own custom Log4j appenders. Want more Java tutorials? Get the Enterprise Java newsletter delivered to your inbox.
Appenders, level, and layout are three aspects of Log4j that can be seen as independent dimensions. I use the term aspect here as a synonym for concern, meaning a piece of interest or focus in a program. In this case, it is easy to define these three concerns based on the questions that each addresses:
Now try considering these aspects together in three-dimensional space. Each point within this space represents a valid system configuration, as shown in Figure 1. (Note that I am offering a slightly simplified view of Log4j: Each point in Figure 1 is actually not a global system-wide configuration, but a configuration for one particular logger. The loggers themselves can be considered as a fourth dimension.)