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.

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 referenced from an Entity.
  • 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, and Qi4j controls the lifecycle.
  • Transient - Short-lived composites that are not persistable. Equals/hashCode/toString are forwarded to the Mixin Type declaring those methods explicitly.
Powered by SiteVisionexternal link.