Skip to content

Reusability

Motivation

Reusability is one of the key design goals for OpenCUI to help business to reduce the cost of building personalized services. In this way, you can use existing components instead of starting from scratch, and always create once, reuse often. There are four different mechanisms available: Import, Clone, Inherit and Compose.

Import

Instead of build functionality from scratch, on OpenCUI, the first choice of acquired functionality is importing the relevant components. Components are shareable libraries provided by all organizations, including OpenCUI. Where there are right components, you only need to import them and provide business dependent data to service your users.

Importing a component is similar to copying a component, with two major differences:

  • You can not modify the components structural parts but the language parts.
  • You can keep it up-to-date with a later version of this component.

For example, io.opencui.core is a public component provided by OpenCUI, which provides the basic functionality of one chatbot. So when creating a new chatbot, io.opencui.core will be automatically imported for the chatbot to work properly. You can update the versions of io.opencui.core when you need it, but you can't modify the structural parts of it.

Clone

Clone is another way of reuse. Instead of building chatbot from empty slate, you can start from existing project by cloning it.

After cloning a project, you will have a copy of it in your target organization. As this copy of project already belongs to your org, members in this org can make any modifications to it. Clone will disconnect the copy from the original project, so new changes on the original project cannot be synchronized.

Inherit

OpenCUI supports inherit/implement on frames, so that you can get new behavior by adding to existing frame instead of building frame from scratch.

There are two types of frames: interface and implementation, which allows you to inherit one frame into another frame. There are multiple inheritances possible:

  • Single Inheritance: In single inheritance, subclasses inherit the features of one superclass.
  • Multi-level Inheritance: In multi-level inheritance, a derived class will be inheriting a base class and as well as the derived class also act as the base class to other class.
  • Hierarchical Inheritance: In hierarchical inheritance, one class serves as a superclass (base class) for more than one subclass.

In OpenCUI, interface frame can inherit many interfaces, every function on the interface is abstract (only signature, no body). Implementation frame can implement many interfaces, but can only inherit one implementation, and must implement all the abstract functions specified in the interface.

Compose

The composition also provides reusability. When there is already a frame that includes the instances and behaviors you want, you can reuse the existing frame as a slot, or use the frame directly in a skill. By doing so, you can get bigger and bigger behaviors.

How to use

Import

To import a component to your project, please follow the subsequent directions:

  1. Click into the component which you would like to import.

  2. In the top-right corner of the page, click Import.

    import icon

  3. In the popup window, select the project where you want to import this component, and save it.

    import project

Clone

To clone a project to your org, please follow the subsequent directions:

  1. Click into the project which you would like to clone.

  2. In the top-right corner of the page, click Clone.

    clone icon

Inherit

To inherit or implement frames:

  1. Navigate to the target frame.

  2. Under the Schema tab, select the frame you would like to inherit or implement in the Implemented section.

    inherit

  3. To declare a frame as an interface, turn on the Interface toggle in the top-right corner of this frame.

    inherit interface

Compose

  1. To add a frame slot, navigate to the target frame. Under the Schema tab, select the frame you want to reuse in the Slots section.

    compose1. In Slots section

    compose frame2. Add frame as slot

  2. To use a frame, navigate to the target skill. Under the Schema tab, select the frame you want to reuse in the Use frame section.

    use frame