Abstractions
Behave-graph is designed as a light weight library that can be plugged into other engines, such as Three.js or Babylon.js. In order to simplify pluggin into other engines, it defines the functionality required for interfacing with these engines as “abstractions”, which can then be implemented by the engines.
This design is inspired by Hardware Abstraction layers present in operating systems. HALs, as they are called, are interfaces which are then implemented by drivers that enable that functionality. HALs allow for operating systems to easily be ported to different systems because the machine specific implementations for the operating systems are cordened off from the main operating system behind these HALs. Behave-graph takes this same approach.
Example abstractions in behave-graph:
For example here is the ILogger abstraction, you can see it is just a standard Typescript interface:
export interface ILogger {
verbose(text: string): void;
info(text: string): void;
warn(text: string): void;
error(text: string): void;
}
Here is the DefaultLogger implementation of the abstraction, you can see it is just a standard Typescript class that implements the above interface:
/* eslint-disable class-methods-use-this */
import { Logger } from '../../../../Diagnostics/Logger.js';
import { ILogger } from '../ILogger.js';
export class DefaultLogger implements ILogger {
verbose(text: string): void {
Logger.verbose(text);
}
info(text: string): void {
Logger.info(text);
}
warn(text: string): void {
Logger.warning(text);
}
error(text: string): void {
Logger.error(text);
}
}