Currently, the framework uses the name Composite for several structural classes like CompositeFactory, CompositeHandler, and CompositeConverter.
While these classes structurally resemble the Gang of Four (GoF) Composite pattern (they implement an interface and hold a collection of children that also implement the interface), their behavior often aligns more closely with the Chain of Responsibility or a Delegator/Router.
For example, when CompositeFactory::create($id) is called, it loops through its child factories, catching InvalidAggregateIdGiven until one succeeds, and then it stops and returns. It essentially asks: 'Can you handle this? No? Next.'
A true GoF Composite typically forwards a method call to all of its children (like a tree of UI components drawing themselves). CompositeUnitOfWork is actually a great example of a true Composite, as commit() flushes all underlying UoWs.
Proposal:
For clarity and architectural precision, consider renaming the classes that loop-and-stop to better reflect their behavior in a future major version:
ChainFactory (or DelegatingFactory) instead of CompositeFactory
ChainHandler (or DelegatingHandler) instead of CompositeHandler
ChainConverter instead of CompositeConverter
This aligns with common framework naming conventions (e.g., Symfony's ChainRouter) and makes the mechanical intent of the class immediately obvious to developers reading the source.
Currently, the framework uses the name
Compositefor several structural classes likeCompositeFactory,CompositeHandler, andCompositeConverter.While these classes structurally resemble the Gang of Four (GoF) Composite pattern (they implement an interface and hold a collection of children that also implement the interface), their behavior often aligns more closely with the Chain of Responsibility or a Delegator/Router.
For example, when
CompositeFactory::create($id)is called, it loops through its child factories, catchingInvalidAggregateIdGivenuntil one succeeds, and then it stops and returns. It essentially asks: 'Can you handle this? No? Next.'A true GoF Composite typically forwards a method call to all of its children (like a tree of UI components drawing themselves).
CompositeUnitOfWorkis actually a great example of a true Composite, ascommit()flushes all underlying UoWs.Proposal:
For clarity and architectural precision, consider renaming the classes that loop-and-stop to better reflect their behavior in a future major version:
ChainFactory(orDelegatingFactory) instead ofCompositeFactoryChainHandler(orDelegatingHandler) instead ofCompositeHandlerChainConverterinstead ofCompositeConverterThis aligns with common framework naming conventions (e.g., Symfony's
ChainRouter) and makes the mechanical intent of the class immediately obvious to developers reading the source.