Search code examples
oopaop

What kinds of concerns are addressed by OOP


I am familiar with the term: Separation of Concerns. It's pretty much advocating modularity in your code.

However, when I was reading about AOP, it specifically says that it allows you separate cross-cutting concerns.

So my question is, if AOP separates cross-cutting concerns, what kind of concerns does OOP separate?


Solution

  • OOP separates concerns that in a real-world scenario would be coupled each other with direct associations.

    For example, a company has many employees, and employees have a salary.

    AOP is about concerns that aren't direct associations but more like sentinels that go beyond object to object relationships.

    A typical sample scenario for AOP is logging. Logging is still represented by an object called Logger but actually the logging action is like an observer that filters out the normal flow and extracts information intercepting the flow behind the scenes.

    While logging can be implemented without AOP, actually you end up dirtying your code with something that has nothing to do with the purpose of a given action (for example: register an user has nothing to do with logging).

    Therefore, you should understand that AOP enforces and improves a good separation of concerns, even taking some requirements out of your eyes, keeping the code simpler.