And to also give a diagram, as you ask:

Asset::Container::KDU1        Response1 Response::Summary1
Del-> Asset::Container::KDU2 (6)    Response2 (5) Response::Summary2 (4)
Asset::Container::KDU3 (3)    Response3 (2) Response::Summary3 (1)

Above KDU2 is a child of KDU1, not in terms of classes, but in terms of lineage. Like a page and a subpage. A Response is the response of a user on a KDU. A Summary is a subclass of Response as described.

Now if I call delete on instance KDU2, I would like to see:

1 deletion of Summary3
2 deletion of Response3
3 deletion of KDU3
4 deletion of Summary2
5 deletion of Response2
6 deletion of KDU2

Kind regards,
Arjan.

On 25/04/18 19:54, Karen Etheridge wrote:
I'm not sure you mean by create a subclass instance on creation of its superclass. Are you intending to have the superclass object have an attribute that holds an instance of the subclass? Perhaps can you show a diagram of what you intend your data to look like after construction is complete?

On Mon, Apr 23, 2018 at 7:53 AM, Arjan Widlak - United Knowledge <ar...@unitedknowledge.nl <mailto:ar...@unitedknowledge.nl>> wrote:

    Hi,

    I tried to use the BUILD method to create an instance of a
    subclass on creating an instance of the parent. This does not work
    and the documentation clearly explains why:

    
http://search.cpan.org/dist/Moose/lib/Moose/Manual/Construction.pod#BUILD_and_parent_classes
    
<http://search.cpan.org/dist/Moose/lib/Moose/Manual/Construction.pod#BUILD_and_parent_classes>

    BUILD methods are called from parent to child and hence this
    triggers a loop.

    I am able to do this with the around method modifier, however I
    need to override the behaviour in the subclass. This is also seems
    error prone and bad practice.

    But if this cannot be done this way, how should it be done? How
    can I always create a subclass instance on creation of it's
    superclass?

    Kind regards,

    Arjan



Reply via email to