5.4. Logical Models

Besides the model that comes from each language-specific parsing process, Sonargraph offers two more models that contain system-based and module-based logical elements which are calculated based on the physical model. These elements are basically logical namespaces and logical programming elements and their calculation is explained with more detail below.

Logical Namespaces

To better understand the concept of Logical Namespaces, it is necessary first to take a look at a couple of examples of physical namespaces:

Physical Namespaces
Figure 5.6. Physical Namespaces

In the image, two source files are displayed, BulkOperationCleanupAction.cs and CollectionAction.cs. The C# parser detects that below each one of them we have the namespace NHibernate.Action; on the physical level they are both independent and have no relation. On the logical level on the other hand, the content will look like this:

Logical Namespaces
Figure 5.7. Logical Namespaces

As it can be inferred from the images, Sonargraph maps all physical namespaces that have the same name into a single logical namespace. This mapping can be system-based or module-based, see Section 5.4.1, “System-Based Logical Model” and Section 5.4.2, “Module-Based Logical Model” for more information.

Logical Programming Elements

Logical Programming Elements construction from Programming Elements is not as simple as logical namespaces construction and it is language-specific.

  • Java: Logical Programming Elements are mapped 1 on 1 to Programming Elements.

  • C/C++: When programming C or C++, there are declarations/definitions for Programming Elements such as classes, structs, unions, routines, variables and namespaces. In this case, the declaration(s) and definition(s) are mapped into a single Logical Programming Element. All other Programming Elements that do not follow the declaration/definition approach will be mapped 1 on 1 to Logical Programming Elements.

  • C#: Logical Programming Elements are mapped 1 on 1 to Programming Elements except for partial types; in their case, all partial types that contribute to the same definition are mapped into a single Logical Programming Element.

The construction of Logical Programming Elements can be system-based or module-based, see Section 5.4.1, “System-Based Logical Model” and Section 5.4.2, “Module-Based Logical Model” for more information.