Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Agent Framework

Derk Norton edited this page Sep 5, 2021 · 4 revisions

Agent Framework

The following UML class diagram shows a high-level view of the abstract component types (yellow) and the agent classes (green) with which they interact.

Bali Agent Framework

Abstract type names are italicized whereas concrete type names are not. This project uses several common Gang of Four Design Patterns including the Composite, Iterator and Visitor patterns as the foundation for the agent framework.

Abstract Classes

Component

It should come as no surprise that most of the classes that makeup the Bali Agent Framework™ are a type of component. Components are used to capture structured information as well as define procedures for doing things. There are three important abstract types of components.

Element

Elements are primitive components that cannot be broken down into subcomponents. Each element has an immutable value. And although the value of an element cannot be changed, many elements provide functions that operate on one or more elements to produce a new element.

String

Some elements, even though they behave as primitive components, are sequential in nature. They consist of strings of characters or numbers that may be iterated over. A string element is still immutable though, unlike collections whose items may be added, modified and removed.

Collection

And finally, collection components contain zero or more items, each of which is also a component. Items can be added and removed from a collection. In fact, an item may be contained in multiple collections at the same time. The lifetime of an item is not necessarily tied to the lifetime of a collection that contains it. Different types of collections serve different purposes, the following flow chart shows some of the more common collection types.

Collection Flow Chart

Agent Classes

Formatter

A formatter uses the visitor pattern to "walk" a component's structure generating an equivalent document string containing the Bali Document Notation™ for the component being formatted.

Parser

Whereas a formatter turns a component into a document, a parser reads a document and generates the equivalent component structure for that document. Parsers and formatters are useful for importing and exporting components in a canonical format.

Visitor

A visitor "walks" a component and all of its subcomponents recursively performing some component type specific operation on each one. Within the Bali Component Framework™ visitors are used to format, duplicate and compile component structures. But custom visitors that perform different tasks can be created as well.

Comparator

A comparator is used to recursively compare two components for equality or relative ordering. When the first component is determined to be less than the second component, a value of -1 is returned. When the first component is greater than the second component, a value of 1 is returned. And when the two components are the same a value of 0 is returned.

Duplicator

A duplicator is used to recursively copy a component. Since elements are immutable they are not copied during the duplication process.

Iterator

An iterator, not surprisingly, is used to iterate over the items in a collection. It can move forward or backwards through the items. The iterator is positioned in the slots between items starting with the slot before the first item and ending in the slot after the last item. From a specific slot it can either retrieve the next item or the previous item. After retrieving the item the iterator moves to the next (or previous) slot.

Clone this wiki locally