Back to TTCN-3 Refactoring Catalog
Group Fragments
Add additional structure to a module by putting logically related declarations into groups.
Motivation
Although TTCN-3 groups have only little semantical meaning, they can help to improve the code in two ways. Firstly, the general structure of a module may be improved as the grouping collects elements that logically belong together. The benefit is good readability and easy navigation if the used TTCN-3 development environment supports navigation using groups. Secondly, proper grouping can be helpful for fine grained import statements since groups can be used in the import restrictions. Therefore, Group Fragments is related to the Restrict Imports refactoring which can make use of groups. Groups are also often candidates to move into another module using the Extract Module / Move Declarations to Another Module refactoring.
Mechanics
- Find declarations which can be logically grouped and find a name for this group reflecting its contents. These are the source declarations. All declarations must be located in the same module. Otherwise, Extract Module / Move Declarations to Another Module should be used beforehand.
- Check whether a target group with the same name or with a corresponding meaning already exists. If not, create the target group with the chosen name.
- Move the source declarations to the target group.
- Compile and validate.
- Consider using the Restrict Imports refactoring afterwards.
Example
The following listing shows a module containing declarations which can be logically grouped by constants, types and structured types.
module ExampleModule {
const integer c_defaultSmtpPort := 25;
const integer c_defaultSmtpSSLPort := 465;
type charstring Answer;
type charstring Question;
type record SmtpMessage {
// ...
}
}
In the refactored version, these declarations are surrounded by groups with names corresponding to the declaration types.
module ExampleModule {
group consts {
const integer c_defaultSmtpPort := 25;
const integer c_defaultSmtpSSLPort := 465;
}
group types {
type charstring Answer;
type charstring Question;
}
group structured {
type record SmtpMessage {
// ...
}
}
}
