Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: OO Pattern Container x Elements and Method Chaining

by jdporter (Paladin)
on Oct 08, 2021 at 15:26 UTC ( [id://11137352]=note: print w/replies, xml ) Need Help??


in reply to OO Pattern Container x Elements and Method Chaining

# method chaining $cont1->get_elem('name')->do_something(); # identical to $elem1 = $cont1->get_elem('name'); $elem1->do_something();

These are in fact identical, other than the temporary variable $elem1. Nothing about method chaining requires that the element know that it's contained by the container.

Replies are listed 'Best First'.
Re^2: OO Pattern Container x Elements and Method Chaining
by LanX (Saint) on Oct 08, 2021 at 15:31 UTC
    Sorry, I forgot to make clear that ->do_something() needs to know the actual Container $cont.

    I wanted to keep it short for clarity.

    update

    It could be solved with a special Method Cascading.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      Ok, but in that case, neither form - with or without the temporary variable - will achieve that. Nothing special gets communicated through method chaining. At least not in POP.

        as I said $cont->get_elem('one') can return another object belonging to a wrapper class "MemberElement" dynamically cloned from $elem0 and enriched with the container info.

        MemberElement could inherit from Element to make sure all methods are transparently available or use AUTOLOAD to delegate methods to $elem0

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137352]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-23 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found