Important points
This package allows you to create Commandable interfaces, which are completely universal. Thus, for example, if an object extends ICommandable and returns a CommandSet, then you can implement a commandable client for this object, using various technologies and with minimal code.
Description
The package main components are:
- Commandable Interfaces – used to make classes with a certain logic and, which are capable of receiving and processing commands in this universal form.
- Command interceptors – modify the message execution pipeline. Command interceptors are used to intercept calls, perform a set of actions, and, optionally, cancel the command’s actual execution by simply returning a result. This logic is used in aspect-oriented programming. Aspect-oriented programming contains perpendicular logic (aspects, such as logging, caching, blocking), which can be removed from the business logic and added to these perpendicular calls.
Moreover, when using interceptors, a command can pass through an execution chain, consisting of interceptors, which can:
- simply take note of the command, notify, log, get metrics, or do some other passive task;
- intercept the command completely and, for example, return a previous record of the call from the cache.
- intercept a command’s return value and, for example, cache the result, so that the next call doesn’t have to be made.
- Intercepted commands are used as pattern decorators that allow behavior to be added to an individual object, dynamically and without affecting the behavior of other objects from the same class. They are represented as regular commands, but run their own logic before calling the actual command.
Typical uses of this package would be intercepting messages and various logging implementations.
Interfaces
ICommandInterceptor
Implements a command wrapped by an interceptor. It allows to build command call chains. The interceptor can alter execution and delegate calls to a following command, which can be intercepted or concrete.
ICommand
An interface for Commands, which are part of the Command design pattern. Each command wraps a method or function and allows to call them in a uniform and safe manner.
ICommandable
An interface for commandable objects, which are part of the command design pattern. The commandable object exposes its functonality as commands and events grouped into a CommandSet. This interface is typically implemented by controllers and is used to auto generate external interfaces.
IEventListener
An interface for listener objects that receive notifications on fired events.
IEvent
An interface for Events, which are part of the Command design pattern. Events allows to send asynchronious notifications to multiple subscribed listeners.
Classes
CommandSet
Contains a set of commands and events supported by a commandable object.
The CommandSet supports command interceptors to extend and the command call chain.
CommandSets can be used as alternative commandable interface to a business object.
It can be used to auto generate multiple external services for the business object
without writing much code.
Command
Concrete implementation of the ICommand interface. Command allows to call a method or function using Command pattern.
Event
Concrete implementation of the IEvent interface. It allows to send asynchronous notifications to multiple subscribed listeners.