Using Object-Oriented Design Principles

The use of widely understood, object-oriented techniques simplifies the design of digital twin models, reduces overall development time, and enhances maintainability. Because a digital twin model encapsulates state information and associated message-processing code, it is naturally represented as a user-defined data type (usually called a class) within an object-oriented language, such as Java or C#. The use of an object-oriented class conveniently encapsulates the data definition and code as a single unit and allows an application to create many instances of this class to track individual data sources. It also lets the application developer take advantage of object-oriented techniques, such as subclasses and hierarchies, to easily refine the behavior of stream-processing applications and simulations. This section explains the distinction between these two techniques.

Consider the digital twin model for a basic controller with class properties (status and event collection) describing the controller’s dynamic data and class methods for analyzing events and performing device commands. (These methods are called during message processing by an outer method not shown here that serves as an entry point for handling incoming messages.) This class can be depicted graphically as follows:

class_design_image

Here’s how this basic controller class could be written in Java:

public class BasicController {
  private List<Event> eventCollection;
  private DeviceStatus status;

  public void start() {/* ... */}
  public void stop() {/* ... */}
  public void handleEvent() {/* ... */}
}

An application also can make use of this class definition to construct various special purpose, real-time digital twin models as sub-classes, taking advantage of the object-oriented technique called inheritance. For example, it can define the model for a hot water valve as a subclass of a basic controller that adds new properties, such as temperature and flow rate, with associated methods for managing them:

inheritance_image

This subclass inherits all of the properties of a basic controller while adding new capabilities to manage specialized controller types. Using this object-oriented approach maximizes code reuse and saves development time.

Here’s a Java example that illustrates how inheritance could be used to create the hot water valve class. It also shows how the hot water valve class can override the implementation of the Start and Stop methods defined by the basic controller:

public abstract class BasicController {
  protected List<Event> eventCollection;
  protected DeviceStatus status;

  public abstract void start();
  public abstract void stop();
  public abstract void handleEvent();
}


public class HotWaterValve extends BasicController {
  private double temperature;
  private double flowRate;

  public double readTemperature() {
    return temperature;
  }

  public double readFlowRate() {
    return flowRate;
  }

  @Override
  public void start() {/* ... */}

  @Override
  public void stop() {/* ... */}

  @Override
  public void handleEvent() {/* ... */}
}

As discussed in the previous section, applications also can build a hierarchy of digital twin models that represent successively higher levels of analysis and management for complex systems, and this hierarchy can further leverage object-oriented techniques.

Consider the following set of interconnected real-time digital twin instances used in managing a hypothetical pump room:

instance_hierarchy_image

In this example, the pump room has two real-time digital twin instances connected directly to their corresponding devices, one for a hot water valve and another for a circuit breaker. These instances are both implemented as subclasses of a basic controller and add properties and methods specific to their device types. They feed telemetry to a higher-level real-time digital twin instance which manages overall operations for the pump room. This pump room controller’s model also can be implemented as a subclass of a basic controller even though it is not connected directly to a device. Note how both object inheritance and hierarchy play separate roles in defining the real-time digital twin models which work together to analyze event streams. Inheritance refines the behavior of a model to customize its actions, and hierarchy simplifies the design of complex systems using interconnected real-time digital twins to process event messages at successively higher levels of abstraction.