lundi 7 décembre 2015

How can we use Command Design Pattern in Android?

How can we use "Command Design pattern" in Android. I read, We can use Command Design pattern in Swings(Java) to handle action on GUI. I want to know that can we implement Command Design pattern in Android for Navigation bar item or too many buttons on same view click handling like Swings(Java) and tell me your view on this point??

In Android like this example:

There are fours buttons on same activity.

  1. Save button
  2. Delete button
  3. Exit button
  4. Edit Button

I want to implement click handling for these four buttons.

1st way : Implement OnClickListener to Activity and write code in onClick method.

2nd way : Make inner class that implements OnClickListener and write code in onClick method.

3rd way : Make four methods and define these method in xml.

4th way : I should use Command Design pattern -->

`
 Interface Command
 {
  execute();
 }

 class Save implements Command
 {
  // write execute code for Save.
 }

 class Delete implements Command
 {
  // write execute code for delete.
 }

 class Edit implements Command
 {
  // write execute code for Edit.
 }

 class Exit implements Command
 {
  // write execute code for exit.
 }

 class HandleAction
 {
   Command command = null;
   handleAction(Command command)
   {
     this.command = command;
   }

   doAction()
   {
     command.execute();
   }
 }`

Same case is for Navigation drawer that have 5-6 options. What is your point on this??

Aucun commentaire:

Enregistrer un commentaire