#!/usr/bin/env perl use strict; use warnings; use Shoe; use Boot; {package Shoe_Rack; sub new{ my $class = shift; my $self = {}; # ... bless $self, $class; return $self; } sub Buy{ my $self = shift; my $TypeToBuy = shift or die "What type to buy ?\n"; $self->{COUNT}{$TypeToBuy}++; # Count whatever we buy my $newthing = $TypeToBuy->new(); push @{$self->{COLLECTION}}, $newthing; return $newthing; } sub getcollection{ my $self = shift; return @{$self->{COLLECTION}}; } 1; } my $s = Shoe->new(); $s->wear_out_sole(); my $b = Boot->new(); $b->wear_out_sole(); my $b2 = Boot->new(); $b2->wear_out_sole(); my $Rack = new Shoe_Rack; my $s1 =$Rack->Buy("Shoe"); $Rack->Buy("Shoe"); $Rack->Buy("Boot"); $Rack->Buy("Boot"); $Rack->Buy("Shoe"); $_->wear_out_sole() for $Rack->getcollection();