a new one that deals with it. In our example, the func-
tion sortQueues is not included in the previously
defined CCDs, because the parameter is an array of
queues.
Module-based Heuristic. From design viewpoint,
the modules define (and implement) functions that
share a common goal or are related by a common
functionality, in our example the module List defines
several functions to deal with list operations. How-
ever, this design principle is not always fulfilled in all
C applications. To our analysis, we consider that the
modules are implemented in a .c and/or .h files. In
this heuristic, depending on the structure of the mod-
ule, there are three possibilities of encoding it in our
model.
1. If the module contains only a set of functions that
are not related to a CCD previously defined, we
will generate a CCD with those functions mapped
as methods and with attributes, if there are de-
clared variables. If not, the defined CCD will have
only methods.
In our example, this heuristic will
create the CCD list as list =
({itemlist[], actual}, {initlist, inserta fter,
insertbe f ore, length, destroy, getitem, list f ull,
listempty, moveactual})
2. If there are only ADTs, and all the functions are
related to those ADTs, we will get one CCD per
each ADT according to the ADT-based heuristics.
In this case, no new CCD will be created.
In our example, the module queue.h is not build-
ing a new CCD because it was already mapped as
the CCDs queue in the ADT-based heuristic.
3. If there is a mixture of declaration of variables
and ADTs, and/or functions related or not to those
ADTs, we will generate CDDs for each ADT with
their corresponding methods - according to the
ADT-based heuristics -, and another CCD with
the same name as the corresponding module with
the declaration of variables and the corresponding
methods not related to a CCD.
In our example, a new CCD named main is cre-
ated containing the method sortQueues that was
not related to any ADT because its argument is
an array, and is not considered in the ADT-based
heuristic. The rest of the functions are related to
the ADT stack and are defined in the correspond-
ing CCD.
Global Variables-based Heuristic. In this heuris-
tic, we analyze each global variable y and a function
f (x
1
, . . . , x
n
) that reads or writes y in its definition,
and then the CCD that contains f adds y as a new
attribute in its definition. Thus, this heuristic does
not create CCDs. With this heuristic, we identify a
cohesion-based situation that helps us to complement
an existing CCD. In our example, this heuristic
finds three global variables referenced in different
functions: MAX is read in full(stack *p), TAM2
is read in dequeue(queue *c, int x) and MAX2
is read in isFull(queue *c). Then, the CCD
stack adds MAX, and the CCD queue adds TAM2
and MAX2 in their respective list of attributes.
Thus, the result of the modified CCDs are: stack =
({top, item[TAM], MAX}, { f ull, empty, push, pop}),
and queue = ({ f ront, rear, length, item2[TAM2], cant,
TAM2, MAX 2}, {enqueue, dequeue, isFull, isEmpty})
In the case of module list.h, this heuristic finds
that MAX3 is read in listfull(), and TAM3 is read in
insertafter() and insertbefore(). Then, these
attributes are added to the CCD list. The result of this
CCD is: list = ({itemlist[], actual, TAM3, MAX3},
{initlist, inserta f ter, insertbe f ore, length, destroy,
getitem, list f ull, listempty, moveactual})
3.2 Expert Mapping: Refactoring
As we stated previously, the mapping from source
code to class definitions is an automatic process, but
the further analysis to decide the final set of classes is
based on expert knowledge and a set of refactorings
done by experts manually.
As we are obtaining an object-oriented model
with associations built only between variables and the
CCD that type them, and we want to take advantages
of good design principles, we could propose improve-
ments in the obtained design. Thus, we describe dif-
ferent possible refactorings that can be applied. Some
of them are based on the Fowler refactorings (Fowler
et al., 1999) and other ones are built based on specific
problems when analyzing the resulting model. Due to
space limitations, we will just mention some of them,
and the reader can see their application in the case
study explained furtherly in this paper: (1) Extract-
ing common arguments from methods, (2) Extracting
algorithms, (3) Abstracting an algorithm: a variant
of Extracting Algorithms, (4) Relocating attributes or
methods, (5) Renaming CCDs, (6) Removing CCDs.
This list is not exhaustive, and just mention the main
ones applied in the case study furtherly.
M2K-AnApproachforanObject-orientedModelofCApplications
253