Composition

Composition is at the heart of COP, and refers to two different levels of constructs;

1. the ability to assemble (compose) objects from smaller pieces, called Fragments.
2. the construction of applications by assembling Composites into Modules and Modules into Layers.

In Qi4j, we use the term Assembly for the second case of composition. See separate chapter.

Composition will allow library authors a new level of flexibility in how functionality is provided to client code. More on that later.

Fragments


There are 4 types of Fragments in Qi4j;
  • Mixin - The state carrying part of a Composite.
  • Constraint - Rules for in and out arguments, typically used for validation.
  • Concern - Interceptor of method calls. General purpose use, often for cross-cutting behaviors.
  • Side Effect - Executed after the method call has been completed, and unable to influence the outcome of the method call.

Composites


There are 4 Composite meta types. Each of these have very different characteristics and it is important to understand these, so the right meta type is used for the right purpose.
  • Entity - Classic meaning. Has an Identity. Is persistable and can be referenced by the Identity. Can act as Aggregate. Entity supports Lifecycle interface. Equals is defined by the Identity.
  • Value - Values are persistable when used in a Property from an Entity. Values are immutable, and equals is defined by the values of its fields.
  • Service - Service is injectable to other composites and java objects. They are not persistable, but if referenced from an Entity or Value, a new reference to the Service will be injected when the Entity/Value is deserialized. Services are singletons. There are 'hosted' and 'imported' Services. The 'hosted' Service has Configuration and its life cycle controlled by the Qi4j runtime, whereas the 'imported' Services are external references.
  • Transient - Short-lived composites that are not persistable. Equals/hashCode/toString are forwarded to the Mixin Type declaring those methods explicitly.

It is not possible to instantiate a class extending org.qi4j.api.composite.Composite. It must be of one of the above meta types.


Qi4j and the Qi4j logo are trademarks of Richard Öberg, Niclas Hedhman and the members of the Qi4j Core Team. See Qi4j licensing for more information.
Powered by SiteVisionexternal link.