in reply to Array copy or encapsulation break?

# ... return $self->{'BigList'}; # ... foreach my $element ( @{ $self->{'Big_List'} } ) { # ...
Where do you see a list of the elements getting returned? You're getting a list with a single scalar - an array reference. You're even dereferencing it yourself in the for loop.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Array copy or encapsulation break?
by shemp (Deacon) on Aug 06, 2003 at 17:01 UTC
    D'oh, you're correct. I don't know what i was thinking. I think i was going to dereference and return in GetBigList(), so that callers don't have direct access to the object's internals. But if i keep GetBigList() private, it should be ok.
      Now, you're entering a bigger question - what are you doing with the return from GetBigList()? It is usually considered better practice to provide that functionality within the class and not expose the internals through getters/setters. Often, getters/setters are used because pure OO is almost never feasible, for non-programming reasons.

      ------
      We are the carpenters and bricklayers of the Information Age.

      The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.