scalp
scalp copied to clipboard
Complex type deconstruction
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.