/ Published in: Perl
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
##1 #Network class relies on two other classes #1.Node class #2.Link, whose objects represent a single unidirectional link to another Node ## package Network; use strict; sub new { my ($class) = @_; } sub node { my ($self, $index) = @_; } sub add_node { my ($self) = @_; } ## #providing the Network class with a destructor that explicitly removes the Links #between Nodes at the appropriate time ## sub DESTROY { my ($self) = @_; foreach my $node ( @{$self->{_nodes}} ) { $node->delete_links(); } } ##2 # Node class, which Network class is relied on ## package Node; use strict; { my $_nodecount=0; } sub new { my ($class) = @_; } sub add_link_to { my ($self, $target) = @_; } ## #in order to remove circular data structure ## sub delete_links { my ($self) = @_; } ##3 #Link class which Node class is relied on ## package Link; use strict; { my $_linkcount=0; } sub new { my ($class) = @_; _to=> $_[1], }, $class; }