Debian Codegraph @

lib/Analizo/Metric/NumberOfChildren.pm

raw
1 package Analizo::Metric::NumberOfChildren;
2 use strict;
3 use parent qw(Class::Accessor::Fast Analizo::ModuleMetric);
4
5
6 =head1 NAME
7
8 Analizo::Metric::NumberOfChildren - Number of Children (NOC) metric
9
10 =head1 DESCRIPTION
11
12 The metric calculation is based on the following article and calculates the
13 number of immediate subclasses subordinate to a class in the hierarchy.
14
15 Article: I<Software Quality Metrics for Object-Oriented Environments> by Linda
16 H. Rosenberg and Lawrence E. Hyatt.
17
18 See the paragraph about Number of Children in the article:
19
20 The number of children is the number of immediate subclasses subordinate to a
21 class in the hierarchy. It is an indicator of the potential influence a class
22 can have on the design and on the system. The greater the number of children,
23 the greater the likelihood of improper abstraction of the parent and may be a
24 case of misuse of subclassing. But the greater the number of children, the
25 greater the reusability since inheritance is a form of reuse. If a class has a
26 large number of children, it may require more testing of the methods of that
27 class, thus increase the testing time.
28
29 =cut
30
31 __PACKAGE__->mk_accessors(qw( model ));
32
33 sub new {
34 my ($package, %args) = @_;
35 my @instance_variables = (
36 model => $args{model}
37 );
38 return bless { @instance_variables }, $package;
39 }
40
41 sub description {
42 return "Number of Children";
43 }
44
45 sub calculate {
46 my ($self, $module) = @_;
47
48 my $number_of_children = 0;
49 for my $other_module ($self->model->module_names) {
50 $number_of_children++ if ($self->_module_parent_of_other($module, $other_module));
51 }
52 return $number_of_children;
53 }
54
55 sub _module_parent_of_other {
56 my ($self, $module, $other_module) = @_;
57 return grep {$_ eq $module} $self->model->inheritance($other_module);
58 }
59
60 1;
61