design-patternsaopcross-cutting-concerns

Cross cutting concern example


What is a good example of a cross-cutting concern? The medical record example on the wikipedia page seems incomplete to me.

Specifically from this example, why would logging lead to code duplication (scattering)? (Besides simple calls such as log("....") everywhere, which doesn't seem like a big deal).

What is the difference between a core concern and a cross-cutting concern?

My end goal is to get a better understanding of AOP.


Solution

  • Before understanding the Crosscutting Concern, we have to understand the Concern.

    A Concern is a term that refers to a part of the system divided on the basis of the functionality.

    There are two types of concerns:

    1. The concerns representing single and specific functionality for primary requirements are known as core concerns.
      OR
      Primary functionality of the system is known as core concerns.
      For example: Business logic
    2. The concerns representing functionalities for secondary requirements are referred to as crosscutting concerns or system-wide concerns.
      OR
      The crosscutting concern is a concern which is applicable throughout the application and it affects the entire application.
      For example: logging, security and data transfer are the concerns which are needed in almost every module of an application, hence they are cross-cutting concerns.

    Courtesy

    enter image description here

    This figure represents a typical application that is broken down into modules. Each module’s main concern is to provide services for its particular domain. However, each of these modules also requires similar ancillary functionalities, such as security logging and transaction management. An example of crosscutting concerns is "logging," which is frequently used in distributed applications to aid debugging by tracing method calls. Suppose we do logging at both the beginning and the end of each function body. This will result in crosscutting all classes that have at least one function.

    (Courtesy)