Template Method Design Mode for android Application Framework Design

Source: Internet
Author: User

Template Method Design Pattern essence: IOC controls reversal, that is, the subclass overrides the method that the parent class wants to override, and then the parent class calls this method. In layman's terms, my father had a desire not fulfilled, so he pinned his hope on his son to achieve it. His son followed the goal set by his father to achieve it, the father satisfies his desires through his son's desire for himself.

The class diagram is as follows:


Use the template mode in android:

Parent Class View:

Public class View {/*** hook operation, empty implement */protected void onDraw (Canvas canvas) {}/ *** hook operation, empty implement */protected void dispatchDraw (Canvas canvas) {}// algorithm skeleton public void draw (Canvas canvas) {if (! VerticalEdges &&! HorizontalEdges) {// Step 1 if (! DirtyOpaque) onDraw (canvas); // Step 2 dispatchDraw (canvas); // step 3 onDrawScrollBars (canvas); return ;}}//......}

Subclass MyView overrides some methods in the parent class:

public class MyView extends View {     public MyView(Context context) {        super(context);    }     @Override    protected void onDraw(Canvas canvas) {        super.onDraw(canvas);    }     @Override    protected void dispatchDraw(Canvas canvas) {        super.dispatchDraw(canvas);    }     }

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.