#!/usr/bin/perl -w
######################################################################
# aggregation.pl
######################################################################
# Perl Power! - Michael Schilli 1998
######################################################################

######################################################################
package Wheel;                     # wheel class

sub new {                        # new wheel
    my $class = shift;
    my $self = {};
                                 # production number 1 ... n
    $self->{'serial'} = defined $serial ? 
                                ++$serial : ($serial=1);

    bless $self, $class;
}

sub movewheel {                     # move wheel
    my $self = shift;

    print "Wheel $self->{'serial'}: is moving!\n";
}

######################################################################
package Car;                    # car class

sub new {                        # new car
    my $class = shift;
    my $self = {};

    foreach $i (1..4) {          # 4 wheels per car
        push(@{$self->{"Wheels"}}, Wheel->new());
    }
    
    bless $self, $class;
}

sub movecar {                      # move car
    my $self = shift;

                                 # move wheels
    foreach $i (@{$self->{"Wheels"}}) {
        $i->movewheel();
    }
}

######################################################################
package main;                    # main program

$car = Car->new();
$car->movecar();

