Share

Helix Router Requirements and Object Design

This article covers the software design for the Helix Router. We will go through the following steps to come up with following object design for the Helix Router:

  • Requirements: State the output of the system design stage in terms of clear requirements for the software module being implemented.
  • Object Discovery: Discover the high level objects from the problem statement.
  • Object Invention: Objects discovered in the previous phase are powerful design abstractions, but some objects need to be invented to "glue" together the discovered objects. This stage also involves refinements to the discovered objects.

Requirements

First step in designing the Helix Router software is to clearly state the requirements for the module. The requirements for the Helix Router are identified below:

  1. Helix Router shall receive packages from the input conveyor belts and route them to Output Conveyor Belts.
  2. All Conveyor belts shall be equipped with a magnetic sensor.
  3. The magnetic sensor associated with the input conveyer belts shall read the magnetic strip of the arriving packages to read product information needed to route the package.
  4. The magnetic sensor associated with the output conveyer belts shall read the magnetic strip of the departing packages to read product information to confirm successful routing of the package.
  5. Helix Router shall raise an alarm if output conveyor belt does not receive a package that was routed from the input conveyor belt.
  6. Routing Table maintained at the router shall be updated when a request is received from the operator.
  7. Router shall support on the fly creation/deletion of conveyor belts.   

Object Discovery

The main objective of this stage is to discover the objects that can be directly identified from the problem itself. In this case we can easily identify the objects from the requirements. We can also get a clue of the interactions between these objects from the requirements. 

The requirements identified above are restated below, the discovered objects are marked in bold and the interactions between the objects are marked in italics.

  1. Helix Router shall receive packages from the Input Conveyor Belts and route them to Output Conveyor Belts.
  2. All Conveyor belts shall be equipped with a magnetic sensor.
  3. The magnetic sensor associated with the input conveyer belts shall read the magnetic strip of the arriving packages to read product information needed to route the package.
  4. The magnetic sensor associated with the output conveyer belts shall read the magnetic strip of the departing packages to read product information to confirm successful routing of the package.
  5. Helix Router shall raise an alarm if output conveyor belt does not receive a package that was routed from the input conveyor belt.
  6. Routing Table maintained at the router shall be updated when a request is received from the operator.
  7. Router shall support on the fly creation/deletion of conveyor belts.   

We have selected the objects by identifying the important nouns in the requirements. The nouns identified should correspond to something tangible. Objects representing abstract concepts should be avoided. Once the objects have been identified, we scan the requirements again to identify the key interactions between these objects. Look for statements identifying actions, these statements point to the interactions between the objects.

The objects identified above are now defined.

Router

Router is the all encompassing object which contains the input and output conveyor belts and the routing table objects. There will be only one instance of the Router object in a Helix Router. Router object will detect packages on input conveyor belts and route them to the output conveyor belt defined for that product.

Input Conveyor Belt

The Input Conveyor Belt object represents an input conveyor belt in the real system. There will be multiple instances of the Input Conveyor Belt object in the Router object. The input conveyor belt object will also contain a single magnetic sensor object for detecting incoming packages.

Output Conveyor Belt

The Output Conveyor Belt object represents an Output conveyor belt in the real system. There will be multiple instances of the Output Conveyor Belt object in the Router object. The output conveyor belt object will also contain a single magnetic sensor object for verifying delivery and correct routing of outgoing packages.

Magnetic Sensor

Magnetic Senor corresponds to a single magnetic sensor object equipped with each conveyor belt. The magnetic sensor will define the interrupt service routine to handle the sensor interrupt from the conveyor belt. The magnetic sensor hardware generates an interrupt when it detects a new package.

Package

Package is a transient object, which will keep track of properties of the package that is being currently routed.

Routing Table

The Routing Table will be a simple object that defines the relationship from a product type to the output conveyor belt. This relationship will be defined by the operator.

Operator

This object represents the operator. It receives operator commands and routes them to the Router object. It also handles the details of sending a response to the operator.

Object Invention

The next stage in object design is to "invent" objects. These objects are needed to "glue" together objects that have been identified during Object Discovery. Invented objects generally do not correspond to anything tangible. They are merely inventions of programmers to simplify design. Since these objects are abstract in nature, they should be considered second class citizens in allocating functionality, i.e. attempt should be made to handle most functionality in discovered objects and assign very little functionality to invented objects.

In this design the only object that needs to be invented is a Manager for Conveyor Belts. This is required as there are several operations like managing creation, deletion, instance management for conveyor belts that cannot be effectively handled by the Router object. In some sense the Conveyor Belt Manager is a helper object for the Router, as Router delegates some functionality to Conveyor Belt Manager.

How did we identify this object? This identification was based on past experience that whenever multiple instances of an object need to be handled, defining a manager to handle the instances is a good idea. For more details, refer to the article on the Manager Design Pattern.

Conveyor Belt Manager

This object is contained in the Router object. The Conveyor Belt Manager manages input and output conveyor belt creation, deletion and modification.

Conveyor Belt

We have seen that Input and Output Conveyor Belts have lot of similarities. All the similarities can be abstracted into a common base class "Conveyor Belt".