Android design mode-appearance mode

Source: Internet
Author: User

Problem: In Android, APK can have, QQ as the representative of plug-in installation update function;

So the problem is, the main system (let's say) call the plug-in installation subsystem, by the subsystem to provide external access, is not a form of appearance mode it?


First, design mode:

1. Definition:

Provides a unified interface for a set of interfaces in a subsystem;

The facade mode defines a high-level interface that makes the subsystem easier to use.

2. Purpose:

Reduce the complexity and dependencies of subsystems. This makes the subsystem easier to use and manage.

Improve the quality of code, code maintainability, Extensibility.


3. Design:

At the beginning of the design, it is necessary to consciously separate two different layers from each other, creating a facade of appearance
Adding a facade can provide a simple interface to reduce dependencies between them.


This allows us to consciously separate the data access and business logic layers from the Android programming, making the design more low-coupling.

Especially for subsystem maintenance, the appearance mode is especially important when the subsystem is getting larger and bigger.


4, The Simple demo:

The first is the subsystem:

Package com.example.demo.facade;/** * Subsystem design * @author Qubian * @data June 9, 2015 * @email [EMAIL protected] * */public ABSTR Act class Lottery {protected abstract string Getlotteryname ();p rotected abstract String getlotterynum ();p rotected Abstra CT String getrandomnum ();} Package Com.example.demo.facade;public class Ssqlottery extends lottery{@Overrideprotected String getlotteryname () { return "SSQ";} @Overrideprotected String Getlotterynum () {return "3";} @Overrideprotected String Getrandomnum () {return "6";}} Package Com.example.demo.facade;public class Dltlottery extends lottery{@Overrideprotected String getlotteryname () { return "DLT";} @Overrideprotected String Getlotterynum () {return "1";} @Overrideprotected String Getrandomnum () {return "7";}}

Then the facade and using:

Package com.example.demo.facade;/** * Appearance mode * Unified External Access * @author Qubian * @data June 9, 2015 * @email [EMAIL protected] * */PUBL IC class Facade {ssqlottery Ssq;public string getlotteryname (string name) {if (Name.equalsignorecase ("SSQ")) {ssq = new ssq Lottery ();} return Ssq.getlotteryname ();}} Package Com.example.demo.facade;import Android.util.log;public class Usefacade {public void use () {facade facade = new FAC Ade (); LOG.I ("TAG", Facade.getlotteryname ("SSQ"));}}

Demo writing seems too simple, but the appearance of the model is actually used more, and relatively simple mode;

According to my understanding;

In a sense, the plug-in installation is understood as a form of appearance, it seems to be simple, the definition is too shallow,

The purpose of the plug-in installation is to start the subsystem, in addition to evoke subsystems, but rarely from the main system calls into the internal subsystem of the method, of course, do not rule out the situation,

If there is not very compatible with the purpose of plug-in installation and update, so there is some no solution.

The question is left here first.



Android design mode-appearance mode

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.