pawaclawczyk / scalp

Some Scala useful classes ported to PHP.
18 stars 1 forks source link

Complex type deconstruction #17

Open pawaclawczyk opened 7 years ago

pawaclawczyk commented 7 years ago

Scalp\PatternMatching\Deconstruction trait provides construct and deconstruct methods, holds internally data that represents construction arguments.

Problem related with current implementation:

  1. Destruction::construct must be called manually with right arguments. It's easy to forget or passed wrong arguments.
  2. Constructor arguments are duplicated, one copy is managed by object and second is hold inside trait.

Improvement proposals:

  1. Destruction::deconstruct could throw exception when trying to deconstruct object that was never constructed.
  2. 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.