Design Mode of android Application Development: appearance Mode

Source: Internet
Author: User

Next, let's learn the appearance mode.
[Html]
<P> appearance mode: provides a unified interface to access a group of interfaces in the subsystem. </P> <p> Create a Car class </p> <pre class = "java" name = "code"> package com. jindegege. car;
 
Public class Car {
 
Public String start (){
Return "the car has started ";
}
 
Public String check_stop (){
Return "Check the brakes ";
}
 
Public String check_box (){
Return "Check tank ";
}
 
Public String check_console (){
Return "Check dashboard ";
}
 
}
 
2. Create a new appearance class (this class provides a unified interface for accessing the Car class interface method)
[Java]
Package com. jindegege. car. facade;
 
Import java. util. ArrayList;
Import java. util. HashMap;
Import java. util. List;
Import java. util. Map;
 
Import com. jindegege. car. Car;
 
 
 
 
Public class Facade {
 
Public Map <String, String> car_do (Car car) {// unified interface method
Map <String, String> data = new HashMap <String, String> ();
/**
* Used to access a group of interface methods in the subsystem
*
*/
String data1 = car. check_box ();
String data2 = car. check_console ();
String data3 = car. check_stop ();
String data4 = car. start ();
Data. put ("data1", data1 );
Data. put ("data2", data2 );
Data. put ("data3", data3 );
Data. put ("data4", data4 );
Return data;
}
}
3. Create an android client and provide xml and activity:
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">
 
<TextView
Android: id = "@ + id/textview01"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"/>
<TextView
Android: id = "@ + id/textview02"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
/>
<TextView
Android: id = "@ + id/textview03"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
/>
<TextView
Android: id = "@ + id/textview04"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
/>
 
</LinearLayout>

Main activity class:
[Java]
Package com. jindegege. facade;
 
 
Import java. util. Map;
 
Import com. jindegege. car. Car;
Import com. jindegege. car. facade. Facade;
 
 
Import android. app. Activity;
Import android. OS. Bundle;
Import android. widget. TextView;
 
Public class FacadeActivity extends Activity {
Private TextView textview01;
Private TextView textview02;
Private TextView textview03;
Private TextView textview04;
Private Facade car_impl;
Private Map <String, String> data;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Textview01 = (TextView) findViewById (R. id. textview01 );
Textview02 = (TextView) findViewById (R. id. textview02 );
Textview03 = (TextView) findViewById (R. id. textview03 );
Textview04 = (TextView) findViewById (R. id. textview04 );
Car_impl = new Facade ();
Data = car_impl.car_do (new Car ());
If (textview01! = Null & data. get ("data1 ")! = Null ){
Textview01.setText (data. get ("data1"). toString ());
}
If (textview02! = Null & data. get ("data2 ")! = Null ){
Textview02.setText (data. get ("data2"). toString ());
}
If (textview03! = Null & data. get ("data3 ")! = Null ){
Textview03.setText (data. get ("data3"). toString ());
}
If (textview04! = Null & data. get ("data4 ")! = Null ){
Textview04.setText (data. get ("data4"). toString ());
}

}
}

Let's take a look at the simple implementation effect:


Isn't it easy? encapsulate the sub-operation with a appearance interface, and then call this interface to call those very complex micro-operations.


From the jindegegesun Column

Related Article

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.