"Paul Archer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> The answer to this is probably out there somewhere, but I haven't run
across
> it yet, so a pointer to a webpage/tutorial/FAQ/whatever would be fine...
>
<snip /
>
> In other words, let's say $main_display is the object that represents what
> is (or should be) currently on the display, and $menu_display is an object
> that gets updated with new menu items. When I do $menu_display->refresh,
the
> data in the $menu_display object needs to be transfered to the
$main_display
> object (and comparisons made, and data written to the LCD).
> I suppose I could have a call like:
> $main_display->refresh_from_other_object(\$menu_display)
> (or something like that...I'm still getting used to the syntax), but that
> seems a waste to have to pass data manually, when the $menu_display object
> should be able to do it itself.
>

My favorite perl OO tutorial is chapters 10-13 of the perl cookbook.

Myself, I would use a solution along the lines of what you propose above,
rather than have a global object. That way, it makes it easy to say stuff
like:

foreach my $display ( @displays ) {
  $menu_display->refresh( $display );
}

I know, youre saying, "Theres only ever one main window!!!" But in my
experience my singletons always end up multiplying :0)

Actually, I probably would have a global object, but it would be a "fall
back" or "default" object. And even then I would set it as a property of my
other object, instead of having to worry about nasty global misbehaving:

sub new {
  my( $class, %args ) = @_
  ...
  my( $self ) = bless( { }, $class );
  $self->{_main} = $args{main};
  ...
  return( $self );
}

if ->refresh() dosent get an argument, thats okay, use the default one:

sub refresh {
  my($self) = shift();
  my($window_to_refresh) = shift() || $self->{_main};
  ...
}

Todd W.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to