Just so that you know, it is very hard to find a use case for linked
lists in Perl where a native array is not a better option.  That said,
why draw a distinction between a node in a linked list and a linked
list?  I would just have one class, that is a reference to a node.
(That itself might have children.)  The one exception is if you wanted
a doubly linked linked list, and wanted to avoid having a memory leak.

For inheritance, usually you just set up @ISA in some way.  Either by
explicit assignment, or with 'use parent'.  (The modern replacement
for 'use base'.  Though I don't know why that needed replacing...)

On Sat, Nov 1, 2014 at 10:36 PM, Adam Russell <[email protected]> wrote:
> I was experimenting with some code, jogging my memory of linked lists.
>
> The approach I took was to define a package LinkedListNode and then a
> package LinkedList.
> My idea is that my LinkedList package is a wrapper around the head node
> which would also define
> some useful methods such as print_list(), remove_node(), and so forth.
>
> I did this by having the constructor for LinkedList create and bless()
> the head node.
> But then I ran into a problem having this object call LinkedListNode
> methods. This was solved
> by making LinkedList a subclass of LinkedListNode with the line
> unshift @ISA, 'LinkedListNode';
>
> Ok, so I am doing what seems to me to be "composition" in OO speak. That
> was my design intention anyway.
> The only way I've found that it works is to use a parent class
> relationship. Does Perl have some
> other way of doing this, using the built in OO system?
> I've read
> http://search.cpan.org/~rjbs/perl-5.18.4/pod/perlootut.pod#Composition
> and it seems that the answer is "No, what I've done is the way to do
> it." but I thought I'd ask in case
> I'm just not getting something?
>
> I only want to use the Perl built in OO system. I am aware Moose (and
> others) have facilities for this.
>
> My code is at http://pastebin.com/8fnxY0Xy if you'd like to take a look.
> Any other questions or comments on this code would be appreciated as
> well. I've been brushing up on a few things
> and am open to comments.
>
> Thanks!
> Adam
>
> _______________________________________________
> Boston-pm mailing list
> [email protected]
> http://mail.pm.org/mailman/listinfo/boston-pm

_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to