Scalp\PatternMatching\Deconstruction trait provides construct and deconstruct methods, holds internally data that represents construction arguments.
Problem related with current implementation:
Destruction::construct must be called manually with right arguments. It's easy to forget or passed wrong arguments.
Constructor arguments are duplicated, one copy is managed by object and second is hold inside trait.
Improvement proposals:
Destruction::deconstruct could throw exception when trying to deconstruct object that was never constructed.
Trait should be replaced with abstract class, __construct should be used to bind type construction arguments. In this case __construct should be protected agains extension in subclasses. Abstract method should be provided to let subclasses do finish object construction.
Scalp\PatternMatching\Deconstruction
trait providesconstruct
anddeconstruct
methods, holds internally data that represents construction arguments.Problem related with current implementation:
Destruction::construct
must be called manually with right arguments. It's easy to forget or passed wrong arguments.Improvement proposals:
Destruction::deconstruct
could throw exception when trying to deconstruct object that was never constructed.__construct
should be used to bind type construction arguments. In this case__construct
should be protected agains extension in subclasses. Abstract method should be provided to let subclasses do finish object construction.