The exploitation of the characteristics of Java's abstract methods of implementing abstract classes---face-tangent

Source: Internet
Author: User

Looking at work today, the code suddenly has the following ideas:

/** * Created by ZQ on 2017/5/25. * Abstract Classes */public abstract class  ABSTRACTC {public    void C () {        D ();        System.out.println ("C_1");        E ();    }    public abstract  void D ();//    {//        System.out.println ("c_1"),//    } public    abstract void E ();//    {//        System.out.println ("c_2");/    }}

  

Key thing the shadow part of the method C ();

The following code takes advantage of the abstract method of abstract classes to implement the idea of wrapping:

/** * Created by ZQ on 2017/5/25.
* Using abstract methods to implement the idea of packaging */public class Abstractway {public static void Main (String [] args) { new ABSTRACTC () { @Override public void D () { System.out.println ("c_2"); } @Override public void E () { System.out.println ("C_3"); } } . C (); }}

As above, in fact in the framework of such as Spring,mybatis, there is the idea of this packaging, in spring, this idea is defined as AOP (aspect-oriented programming), such as the implementation of spring annotations (such as: @[email protected]), the code   System.out.println ("C_1"); Instead of a "reflection" method, you can perform pre-set business logic, such as access statistics, logging, and so on before and after executing a method.

The exploitation of the characteristics of Java's abstract methods of implementing abstract classes---face-tangent

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.