Announcement Announcement Module
Collapse
No announcement yet.
Pointcut on Interface, or Abstract class, or concrete class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pointcut on Interface, or Abstract class, or concrete class

    Would like to know what is the best practice and why on the following scenarion.

    Should pointcut be applied on interface, or abstract class or on the concrete class?

    Interface1 is an interface which holds all the business methods.

    Code:
    Abstract1 implements Interface1
    Abstract1 is an abstract class because it does not implement all the methods in Intefrace1. Abstract1 does not have any abstract method.
    Code:
    Concrete1 extends Abstract1
    Concrete1 is a concrete class that implements all the methods of Interface1.

    In reality, I could apply point-cut on the methods of Interface1. In that way, I do not have to specify in pointcut on the methods of the concrete classes (e.g. Concrete1, Concrete2). Interface could also reside in another project (e.g. Core project). Concrete1, Concrete2 classes could be in separate projects (e.g. proj1, proj2) that includes Core project.

    I may not be able to apply pointcut on Abstract1 (even on non abstract methods of Abstract1), as it does not have all the methods that I need.

    Only Interface1 and Concrete1, Concrete2 etc. have all the methods that I need on which I could apply pointcuts.

    From my reading, it is recommended that I apply pointcut on the concrete classes over Interface, or on abstract class because of proxy etc.

    What ara the implications of applying pointcut on Interface, as opposed to Concrete class (or, Abstract class)?

  • #2
    Originally posted by sunfun View Post
    From my reading, it is recommended that I apply pointcut on the concrete classes over Interface, or on abstract class because of proxy etc.
    Any references to the reasons to do so?


    Originally posted by sunfun View Post
    What ara the implications of applying pointcut on Interface, as opposed to Concrete class (or, Abstract class)?
    You should define pointcuts in terms of interfaces whenever possible (e.g. if you want to cover all implementations of particular interface and spread that coverage to the implementations added at the future).

    The only drawback in AOP programming with interfaces is annotation-based approach - interface annotations are not inherited. Hence, if you build for example transactions via @Transactional you should mark implementation classes, not interfaces.

    Comment


    • #3
      I agree with what Denis says.

      I will add that the most important consideration for designing pointcut is the expected semantics. The first question to ask is "what do I want this pointcut to select".

      -Ramnivas

      Comment

      Working...
      X