Wednesday, December 23, 2015

Design pattern

Design pattern is a well described solution to a common software problem.

- Leads to faster development
- Helps to build robust and highly maintainable code.

Creational Design Patterns:

1. Singleton Pattern 
    Only one instance of the class exists in the java virtual machine.
       - Bill Pugh Method is best approach in creating singleton
       Android Ex: ActivityManager, Context, LocationManager, TelephonyManager etc..

2. Factory Pattern
3. Abstract Factory Pattern
4. Builder Pattern
      Provides a way to build the complex object step-by-step and provide a method that will actually return the final Object. Android Ex: Notification.Builder, AlertDialog.Builder

5. Prototype Pattern
    Provides a mechanism to copy the original object to a new object and then modify it according to our needs. This pattern uses java cloning to copy the object.
       Android Ex: Notification (provides method clone)

Structural Design Patterns:

1. Adapter Pattern
      Two unrelated interfaces can work together. The object that joins these unrelated interface is called an Adapter. Android Ex. ArrayAdapter, BaseAdapter etc..

2. Composite Pattern
      Usefull when we have to represent a part-whole hierarchy.
       Android Ex: View

3. Proxy Pattern
      Provides a placeholder for another object to provide controlled access of a functionality.

4. Flyweight Pattern
      Reduces the memory by sharing objects when we create a lot of Objects of a class.
       JavaEx: String Pool 
       Android Ex: Message

5. Facade Pattern
      Provide a wrapper interface on top of the existing interface to help client application
       Android Ex: MediaPlayer

6. Bridge Pattern
      When we have interface hierarchies in both interfaces as well as implementations, then builder design pattern is used to decouple the interfaces from implementation and hiding the implementation details from the client programs. ( Ex: Color/ Share interface hierachy )

7. Decorator Pattern
      Modifies the functionality of an object at runtime
       Java Ex: FileInputStream, BufferedInputStream, FileReader, BufferedReader etc..

Behavioral Design Patterns
1. Template Method Pattern
      It’s used to create a method stub and deferring some of the steps of implementation to the subclasses.

2. Mediator Pattern

3. Chain of Responsibility Pattern
      Usefull to achieve lose coupling in software design where a request from client is passed to a chain of objects to process them.
       Android Ex: Ordered Broadcast

4. Observer Pattern
      Android Ex: Broadcast receiver

5. Strategy Pattern
6. Command Pattern
      Used to implement lose coupling in a request-response model.

7. State Pattern
      Usefull when an Object change its behavior based on its internal state.
       Ex: TV Remote

8. Visitor Pattern
9. Interpreter Pattern
10. Iterator Pattern
        Provides a standard way to traverse through a group of Objects.
          Ex: Java Iterator

11. Memento Pattern


Others ( from Android )
  1. View Holder - Making ListView Scrolling Smooth
  2. MVC (Model View Controller)
  3. MVP (Model View Presenter)
  4. MVVM (Model View View Model)
  


Reference: 
1. Journaldev
2. Making ListView Scrolling Smooth - http://developer.android.com/training/improving-layouts/smooth-scrolling.html

No comments:

Post a Comment