COMMAND - TV article (original)

xiaoxiao2021-03-06  91

Design mode Command - TV articles

Every night, robbing TV remote control is our reserved program. The daughter likes to see cartoon screen, my wife likes to watch TV drama, I like to watch football screen. So who controlled the remote control, is equal to achieving his own show. Hey, in fact, every time I succeeded, and she still said that there is a word: "What should I make small?", You see this child, I don't know who to learn. Then the remote control is a wife, and finally it will be turned to me. When I was happy to press the football screen, the announcer said: "Today's program is here, please watch tomorrow!", I felt gently.

Everyone knows that the TV remote control program panel is composed of a program button, and can switch to the corresponding program screen by selecting the corresponding program button.

Let's take a look at how to select the process of selecting the program screen through the remote control button.

1. Here, first define the remoteControlButton interface:

Public interface remotecontrolbutton {

Public Abstract void selectprogram (); // Select a program screen

}

2, then define the implementation class of the remoteControlButton interface:

A: Cartoon Program button (CartonprogramButton) class:

Public Class Cartonprogrambutton Implements RemoteControlButton {

Public void selectprogram () {

System.out.println ("selected cartoon screen!");

}

}

B: TV PlanprogramButton class:

Public Class TVplanprogrambutton Implements RemoteControlButton {

Public void selectprogram () {

System.out.println ("selected TV drama!");

}

}

C: Football program button (FootprogramButton) class:

Public Class Footprogrambutton Implements RemoteControlButton {

Public void selectprogram () {

System.out.println ("Select the football screen!");

}

}

3, Remote Control Program Panel (Programpan) Class: Used to control program buttons, display show

Public class programpan {

Public static list programlist () {

List list = new arraylist (); // shows the screen button list

List.add (new cartonprogrambutton ()); // cartoon screen button

List.add (new tvplanprogrambutton ()); // TV drama screen button

List.add (new footprogrambutton ()); // football screen button

Return List;

}

}

4, write test classes:

Public class testcommand {

Public static void main (String [] args) {

List list = programpan.programlist (); // Get the program screen button for (item it = list.iterator (); it.hasnext ();)

(RemoteControlButton) it.next ()). SelectProgram (); // Select the corresponding program in the program screen

}

}

5. Description:

A: Command is white, it is by selecting one command and then performs the corresponding action.

B: Command is a typical mode of the behavior package, in this case, we can see the purpose of our TV show through the remote control program panel (Programpan) package class.

C: Command mode and facade seem to be similar. It is accessed by packaging classes. How to distinguish, I am also confused about this. D: The Command mode is the object container class with Collection, putting other classes in the same way to implement a group of operations for packaging. The FACADE mode is to put a function of the operation, set it with a unified, external interface, such as: package database operation, email operation, and more. 6, thank you for gratitude to Changlich netizen interpretation of the difference between Command mode and FACADE mode, hereby joining this interpretation into the description, I hope to help everyone. Thank you again for your support.

转载请注明原文地址:https://www.9cbs.com/read-106952.html

New Post(0)