Design Patterns(十三) Command

Command pattern is a data driven design pattern and falls under behavioral pattern category. A request is wrapped under an object as command and passed to invoker object. Invoker object looks for the appropriate object which can handle this command and passes the command to the corresponding object which executes the command.

Algorithm Shell Sort

Shell Sort is mainly a variation of Insertion Sort. In insertion sort, we move elements only one position ahead. When an element has to be moved far ahead, many movements are involved. The idea of shell Sort is to allow exchange of far items. In shell Sort, we make the array h-sorted for a large value of h. We keep reducing the value of h until it becomes 1. An array is said to be h-sorted if all sublists of every h’th element is sorted.

Algorithm Insertion Sort

Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain.

Algorithm Bubble Sort

Bubblesort is an elementary sorting algorithm. The idea is to imagine bubbling the smallest elements of a (vertical) array to the top; then bubble the next smallest; then so on until the entire array is sorted. Bubble sort is worse than both insertion sort and selection sort. It moves elements as many times as insertion sort (bad) and it takes as long as selection sort (bad). On the positive side, bubble sort is easy to understand. Also there are highly improved variants of bubble sort.

Design Patterns(九) Facade

Facade pattern hides the complexities of the system and provides an interface to the client using which the client can access the system. This type of design pattern comes under structural pattern as this pattern adds an interface to existing system to hide its complexities.This pattern involves a single class which provides simplified methods required by client and delegates calls to methods of existing system classes.