ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Design Patterns
Design Pattern 
? A design pattern is just a convenient way of reusing object-oriented 
(OO) code between projects and programmers. A common pattern in 
early literature on programming frameworks is Model-View- 
Controller (MVC) for Smalltalk [Krasner and Pope, 1988], which 
divides the user interface problem into three parts.
Design Pattern Definitions 
1. Design patterns are recurring solutions to design problems you see over and 
over. 
2. Design patterns constitute a set of rules describing how to accomplish certain 
tasks in the realm of software development. 
3. Design patterns focus more on reuse of recurring architectural design themes, 
while frameworks focus on detailed design... and implementation 
4. A pattern addresses a recurring design problem that arises in specific design 
situations and presents a solution to it. 
5. Patterns identify and specify abstractions the at are above the level of single 
classes and instances, or of components. 
6. Design patterns are not just about the design of objects; they are 
also about interaction between objects. One possible view of 
some of these patterns is to consider them as communication 
patterns
Design Pattern Continue 
? The design patterns divides into three types: 
? Creational patterns: create objects for you, rather than your having 
to instantiate objects directly. Your program gains more flexibility in 
deciding which objects need to be created for a given case. 
? Structural patterns: help you compose groups of objects into larger 
structures, such as complex user interfaces and accounting data. 
? Behavioral patterns: help you to define the communication between 
objects in your system and how the flow is controlled in a complex 
program.
Division Of Design pattern 
Creational Pattern 
1.Singleton 
2.Factory 
3.Factory Method 
4.Abstract Factory 
5.Builder 
6.Prototype 
7.Object Pool 
? Structural patterns 
1.Adapter 
2.Bridge 
3.Composite 
4.Decorator 
5.Flyweight 
6.Proxy 
? Behavioral patterns: 
1. Chain of Responsibility 
2. Command 
3. Interpreter 
4. Iterator 
5. Mediator 
6. Memento 
7. Observer 
8. Strategy 
9. Template Method 
10.Visitor 
11.Null Object
Design Pattern use in Android 
Three most common Design Patterns use in Android 
1)MVC (Model View Controller) 
2)MVP (Model View Presenter) 
3)MVVM (Model-View-View Model)
MVC (Model View Control) 
1. Data Model, which contains the computational parts of the program 
2. View, which presents the user interface 
3. Controller, which interacts between the user and the view 
4. Each aspect of the problem is a separate object , and each has its 
own rules for managing its data. 
5. Communication between the user, the graphical user interface 
( GUI), and the data should be carefully controlled
Model View Controller for Android 
? Controllers are the activities themselves which contain all the business 
logic done in the application. 
? Models are our entities which describe the components of our apps. 
? Views can be done in XML layouts.
Design pattern in android
MVP (Model View Presenter) 
Most Important Design Patter 
? The MVP pattern allows separate the presentation layer from the logic. 
? Model-View-Presenter pattern is a perfect fit for android development. Since 
the Views role in this pattern are: 
? serving as a entry point 
? rendering components 
? routing user events to the presenter
MVP (Model View Presenter) 
Most Important Design Patter in Android 
The presenter 
The presenter is responsible to act as the middle man between view and model. It retrieves data from 
the model and returns it formatted to the view. 
The View 
The view, usually implemented by an Activity (it may be a Fragment, a View¡­ depending on how the app 
is structured), will contain a reference to the presenter. 
The only thing that the view will do is calling a method from the presenter every time there is an 
interface action (a button click for example). 
The model 
In an application with a good layered architecture, this model would only be the gateway to the domain 
layer or business logic.
Design pattern in android
Difference B/w MVC & MVP 
MVC MVP 
UI Presentation Pattern focus on separation of view with 
Model 
Based on MVC (UI Presentation Pattern) 
Separation of responsibility between three components: 
1.View - responsible for rendering UI 
elements 
2.Controller - responsible for responding to 
view actions 
3.Model - responsible for business behavior 
and state management 
Separation of responsibility between four components: 
1.View - responsible for rendering UI 
elements 
2.View Interface - responsible for loose 
coupling between view and model 
3.Presenter - responsible for view and model 
interaction 
4.Model - responsible for business behavior 
and state management
Difference B/w MVC & MVP Continue 
MVC MVP 
Fairly loose coupling Comparatively high degree of loose coupling 
Limited unit testing Comparatively high degree of ease of unit testing 
Controller is behavior based and multiple views 
can share single controller 
Usually one view has one presenter (1-1 mapping). 
Multiple presenters would be associated with a 
complex view 
Identifies which view to update Presenter will update its associated view
Design pattern in android
The Following Android Classes uses Design 
Patterns 
1) View Holder uses Singleton Design Pattern 
2) Intent uses Factory Design Pattern 
3) Adapter uses Adapter Design Pattern 
4) Broadcast Receiver uses Observer Design Pattern 
5) View uses Composite Design Pattern 
6) Media FrameWork uses Fa?ade Design Pattern
Creational Patterns
Singleton Pattern 
? Sometimes it's important to have only one instance for a class. For 
example, in a system there should be only one window manager (or only a 
file system or only a print spooler). Usually singletons are used for 
centralized management of internal or external resources and they 
provide a global point of access to themselves. 
? The singleton pattern is one of the simplest design patterns: it involves 
only one class which is responsible to instantiate itself, to make sure it 
creates not more than one instance; in the same time it provides a global 
point of access to that instance. In this case the same instance can be used 
from everywhere, being impossible to invoke directly the constructor each 
time.
1st Way 
? class Singleton 
? { 
? private static Singleton instance; 
? private Singleton() { } 
? public static synchronized Singleton 
getInstance() 
? { 
? if (instance == null) 
? instance = new Singleton(); 
? return instance; 
? } 
? public void doSomething() { } 
? } 
2nd Way 
? class Singleton 
? { 
? private static Singleton instance = new Singleton(); 
? private Singleton() 
? { 
? ... 
? } 
? public static synchronized Singleton getInstance() 
? { 
? return instance; 
? } 
? public void doSomething() 
? { 
? ... 
? } 
? }
Factory Pattern 
? When a interface does not know which sub-class of objects initilize it
Factory Pattern example 2
Structural Patterns
Adapter Design Pattern 
? The adapter pattern is adapting between classes and objects. Like any 
adapter in the real world it is used to be an interface, a bridge 
between two objects. 
? it's used to identifying a simple way to realize relationships between 
entities. 
? The main use of this pattern is when a class that you need to use 
doesn't meet the requirements of an interface.
Design pattern in android
Composite Design Pattern 
? Composite pattern is used where we need to treat a group of objects 
in similar way as a single object. Composite pattern composes objects 
in term of a tree structure to represent part as well as whole 
hierarchy 
? This pattern creates a class contains group of its own objects. This 
class provides ways to modify its group of same objects
Design pattern in android
Behavioral patterns
Observer Design Pattern 
Observer pattern is one of the behavioral design pattern 
Observer design pattern is useful when you are interested in the state 
of an object and want to get notified whenever there is any change 
In observer pattern, the object that watch on the state of another 
object are called Observer and the object that is being watched is 
called Subject
Design pattern in android
Ad

Recommended

Clean architecture: Android
Clean architecture: Android
intive
?
Events and Listeners in Android
Events and Listeners in Android
ma-polimi
?
Android UI
Android UI
nationalmobileapps
?
[Final] ReactJS presentation
[Final] ReactJS presentation
ºé Åô·¢
?
Android activities & views
Android activities & views
ma-polimi
?
Angular IO
Angular IO
Jennifer Estrada
?
Angular 9
Angular 9
Raja Vishnu
?
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
Knoldus Inc.
?
Learn react-js
Learn react-js
C...L, NESPRESSO, WAFAASSURANCE, SOFRECOM ORANGE
?
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha Gadkari
Surekha Gadkari
?
Intents in Android
Intents in Android
ma-polimi
?
Angularjs PPT
Angularjs PPT
Amit Baghel
?
Mobile Application Development With Android
Mobile Application Development With Android
guest213e237
?
React JS: A Secret Preview
React JS: A Secret Preview
valuebound
?
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
Osahon Gino Ediagbonya
?
Visual Studio
Visual Studio
university of education,Lahore
?
Mobile Application Development Process
Mobile Application Development Process
ChromeInfo Technologies
?
Responsive web design
Responsive web design
Russ Weakley
?
Android ppt
Android ppt
Pooja Garg
?
Angular 5 presentation for beginners
Angular 5 presentation for beginners
Imran Qasim
?
§°§ã§à§Ò§Ö§ß§ß§à§ã§ä§Ú §ä§Ö§ã§ä§Ú§â§à§Ó§Ñ§ß§Ú§ñ §Þ§à§Ò§Ú§Ý§î§ß§í§ç §á§â§Ú§Ý§à§Ø§Ö§ß§Ú§Û (Android, iOS)
§°§ã§à§Ò§Ö§ß§ß§à§ã§ä§Ú §ä§Ö§ã§ä§Ú§â§à§Ó§Ñ§ß§Ú§ñ §Þ§à§Ò§Ú§Ý§î§ß§í§ç §á§â§Ú§Ý§à§Ø§Ö§ß§Ú§Û (Android, iOS)
§¿§Ý§î§Ó§Ú§ß§Ñ §³§Ñ§Ü§Ñ§Ö§Ó§Ñ
?
Model view controller (mvc)
Model view controller (mvc)
M Ahsan Khan
?
Android MVVM
Android MVVM
David Estivariz Pierola
?
Software Patterns
Software Patterns
kim.mens
?
Web Designing
Web Designing
BALUJAINSTITUTE
?
Java spring framework
Java spring framework
Rajiv Gupta
?
Angular modules in depth
Angular modules in depth
Christoffer Noring
?
Introduction to Angularjs
Introduction to Angularjs
Manish Shekhawat
?
Design patterns in android
Design patterns in android
Zahra Heydari
?
Design Patterns
Design Patterns
Nadeesha Thilakarathne
?

More Related Content

What's hot (20)

Learn react-js
Learn react-js
C...L, NESPRESSO, WAFAASSURANCE, SOFRECOM ORANGE
?
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha Gadkari
Surekha Gadkari
?
Intents in Android
Intents in Android
ma-polimi
?
Angularjs PPT
Angularjs PPT
Amit Baghel
?
Mobile Application Development With Android
Mobile Application Development With Android
guest213e237
?
React JS: A Secret Preview
React JS: A Secret Preview
valuebound
?
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
Osahon Gino Ediagbonya
?
Visual Studio
Visual Studio
university of education,Lahore
?
Mobile Application Development Process
Mobile Application Development Process
ChromeInfo Technologies
?
Responsive web design
Responsive web design
Russ Weakley
?
Android ppt
Android ppt
Pooja Garg
?
Angular 5 presentation for beginners
Angular 5 presentation for beginners
Imran Qasim
?
§°§ã§à§Ò§Ö§ß§ß§à§ã§ä§Ú §ä§Ö§ã§ä§Ú§â§à§Ó§Ñ§ß§Ú§ñ §Þ§à§Ò§Ú§Ý§î§ß§í§ç §á§â§Ú§Ý§à§Ø§Ö§ß§Ú§Û (Android, iOS)
§°§ã§à§Ò§Ö§ß§ß§à§ã§ä§Ú §ä§Ö§ã§ä§Ú§â§à§Ó§Ñ§ß§Ú§ñ §Þ§à§Ò§Ú§Ý§î§ß§í§ç §á§â§Ú§Ý§à§Ø§Ö§ß§Ú§Û (Android, iOS)
§¿§Ý§î§Ó§Ú§ß§Ñ §³§Ñ§Ü§Ñ§Ö§Ó§Ñ
?
Model view controller (mvc)
Model view controller (mvc)
M Ahsan Khan
?
Android MVVM
Android MVVM
David Estivariz Pierola
?
Software Patterns
Software Patterns
kim.mens
?
Web Designing
Web Designing
BALUJAINSTITUTE
?
Java spring framework
Java spring framework
Rajiv Gupta
?
Angular modules in depth
Angular modules in depth
Christoffer Noring
?
Introduction to Angularjs
Introduction to Angularjs
Manish Shekhawat
?
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha Gadkari
Surekha Gadkari
?
Intents in Android
Intents in Android
ma-polimi
?
Mobile Application Development With Android
Mobile Application Development With Android
guest213e237
?
React JS: A Secret Preview
React JS: A Secret Preview
valuebound
?
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
Osahon Gino Ediagbonya
?
Responsive web design
Responsive web design
Russ Weakley
?
Angular 5 presentation for beginners
Angular 5 presentation for beginners
Imran Qasim
?
§°§ã§à§Ò§Ö§ß§ß§à§ã§ä§Ú §ä§Ö§ã§ä§Ú§â§à§Ó§Ñ§ß§Ú§ñ §Þ§à§Ò§Ú§Ý§î§ß§í§ç §á§â§Ú§Ý§à§Ø§Ö§ß§Ú§Û (Android, iOS)
§°§ã§à§Ò§Ö§ß§ß§à§ã§ä§Ú §ä§Ö§ã§ä§Ú§â§à§Ó§Ñ§ß§Ú§ñ §Þ§à§Ò§Ú§Ý§î§ß§í§ç §á§â§Ú§Ý§à§Ø§Ö§ß§Ú§Û (Android, iOS)
§¿§Ý§î§Ó§Ú§ß§Ñ §³§Ñ§Ü§Ñ§Ö§Ó§Ñ
?
Model view controller (mvc)
Model view controller (mvc)
M Ahsan Khan
?
Software Patterns
Software Patterns
kim.mens
?
Java spring framework
Java spring framework
Rajiv Gupta
?

Similar to Design pattern in android (20)

Design patterns in android
Design patterns in android
Zahra Heydari
?
Design Patterns
Design Patterns
Nadeesha Thilakarathne
?
Architectural Design & Patterns
Architectural Design & Patterns
Inocentshuja Ahmad
?
Design patterns
Design patterns
Mobicules Technologies
?
Design Patterns every Android developer should know
Design Patterns every Android developer should know
muratcanbur
?
UI Design Patterns
UI Design Patterns
aamiralihussain
?
Android DesignArchitectures.pptx
Android DesignArchitectures.pptx
SafnaSaff1
?
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | Edureka
Edureka!
?
Design Pattern with Actionscript
Design Pattern with Actionscript
Daniel Swid
?
Design patterns
Design patterns
Mobicules Technologies
?
Lecture11
Lecture11
artgreen
?
Java Design Patterns Interview Questions PDF By ScholarHat
Java Design Patterns Interview Questions PDF By ScholarHat
Scholarhat
?
5 Design Patterns Explained
5 Design Patterns Explained
Prabhjit Singh
?
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVM
Dong-Ho Lee
?
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
anguraju1
?
ActionScript Design Patterns
ActionScript Design Patterns
Yoss Cohen
?
Mastering Design Patterns in Java: A Comprehensive Guide
Mastering Design Patterns in Java: A Comprehensive Guide
JAVATPOINT
?
Design patterns
Design patterns
F(x) Data Labs Pvt Ltd
?
Design patterns
Design patterns
mudabbirwarsi
?
Design patterns
Design patterns
Akhilesh Gupta
?
Design patterns in android
Design patterns in android
Zahra Heydari
?
Design Patterns every Android developer should know
Design Patterns every Android developer should know
muratcanbur
?
Android DesignArchitectures.pptx
Android DesignArchitectures.pptx
SafnaSaff1
?
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | Edureka
Edureka!
?
Design Pattern with Actionscript
Design Pattern with Actionscript
Daniel Swid
?
Java Design Patterns Interview Questions PDF By ScholarHat
Java Design Patterns Interview Questions PDF By ScholarHat
Scholarhat
?
5 Design Patterns Explained
5 Design Patterns Explained
Prabhjit Singh
?
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVM
Dong-Ho Lee
?
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
anguraju1
?
ActionScript Design Patterns
ActionScript Design Patterns
Yoss Cohen
?
Mastering Design Patterns in Java: A Comprehensive Guide
Mastering Design Patterns in Java: A Comprehensive Guide
JAVATPOINT
?
Ad

Design pattern in android

  • 2. Design Pattern ? A design pattern is just a convenient way of reusing object-oriented (OO) code between projects and programmers. A common pattern in early literature on programming frameworks is Model-View- Controller (MVC) for Smalltalk [Krasner and Pope, 1988], which divides the user interface problem into three parts.
  • 3. Design Pattern Definitions 1. Design patterns are recurring solutions to design problems you see over and over. 2. Design patterns constitute a set of rules describing how to accomplish certain tasks in the realm of software development. 3. Design patterns focus more on reuse of recurring architectural design themes, while frameworks focus on detailed design... and implementation 4. A pattern addresses a recurring design problem that arises in specific design situations and presents a solution to it. 5. Patterns identify and specify abstractions the at are above the level of single classes and instances, or of components. 6. Design patterns are not just about the design of objects; they are also about interaction between objects. One possible view of some of these patterns is to consider them as communication patterns
  • 4. Design Pattern Continue ? The design patterns divides into three types: ? Creational patterns: create objects for you, rather than your having to instantiate objects directly. Your program gains more flexibility in deciding which objects need to be created for a given case. ? Structural patterns: help you compose groups of objects into larger structures, such as complex user interfaces and accounting data. ? Behavioral patterns: help you to define the communication between objects in your system and how the flow is controlled in a complex program.
  • 5. Division Of Design pattern Creational Pattern 1.Singleton 2.Factory 3.Factory Method 4.Abstract Factory 5.Builder 6.Prototype 7.Object Pool ? Structural patterns 1.Adapter 2.Bridge 3.Composite 4.Decorator 5.Flyweight 6.Proxy ? Behavioral patterns: 1. Chain of Responsibility 2. Command 3. Interpreter 4. Iterator 5. Mediator 6. Memento 7. Observer 8. Strategy 9. Template Method 10.Visitor 11.Null Object
  • 6. Design Pattern use in Android Three most common Design Patterns use in Android 1)MVC (Model View Controller) 2)MVP (Model View Presenter) 3)MVVM (Model-View-View Model)
  • 7. MVC (Model View Control) 1. Data Model, which contains the computational parts of the program 2. View, which presents the user interface 3. Controller, which interacts between the user and the view 4. Each aspect of the problem is a separate object , and each has its own rules for managing its data. 5. Communication between the user, the graphical user interface ( GUI), and the data should be carefully controlled
  • 8. Model View Controller for Android ? Controllers are the activities themselves which contain all the business logic done in the application. ? Models are our entities which describe the components of our apps. ? Views can be done in XML layouts.
  • 10. MVP (Model View Presenter) Most Important Design Patter ? The MVP pattern allows separate the presentation layer from the logic. ? Model-View-Presenter pattern is a perfect fit for android development. Since the Views role in this pattern are: ? serving as a entry point ? rendering components ? routing user events to the presenter
  • 11. MVP (Model View Presenter) Most Important Design Patter in Android The presenter The presenter is responsible to act as the middle man between view and model. It retrieves data from the model and returns it formatted to the view. The View The view, usually implemented by an Activity (it may be a Fragment, a View¡­ depending on how the app is structured), will contain a reference to the presenter. The only thing that the view will do is calling a method from the presenter every time there is an interface action (a button click for example). The model In an application with a good layered architecture, this model would only be the gateway to the domain layer or business logic.
  • 13. Difference B/w MVC & MVP MVC MVP UI Presentation Pattern focus on separation of view with Model Based on MVC (UI Presentation Pattern) Separation of responsibility between three components: 1.View - responsible for rendering UI elements 2.Controller - responsible for responding to view actions 3.Model - responsible for business behavior and state management Separation of responsibility between four components: 1.View - responsible for rendering UI elements 2.View Interface - responsible for loose coupling between view and model 3.Presenter - responsible for view and model interaction 4.Model - responsible for business behavior and state management
  • 14. Difference B/w MVC & MVP Continue MVC MVP Fairly loose coupling Comparatively high degree of loose coupling Limited unit testing Comparatively high degree of ease of unit testing Controller is behavior based and multiple views can share single controller Usually one view has one presenter (1-1 mapping). Multiple presenters would be associated with a complex view Identifies which view to update Presenter will update its associated view
  • 16. The Following Android Classes uses Design Patterns 1) View Holder uses Singleton Design Pattern 2) Intent uses Factory Design Pattern 3) Adapter uses Adapter Design Pattern 4) Broadcast Receiver uses Observer Design Pattern 5) View uses Composite Design Pattern 6) Media FrameWork uses Fa?ade Design Pattern
  • 18. Singleton Pattern ? Sometimes it's important to have only one instance for a class. For example, in a system there should be only one window manager (or only a file system or only a print spooler). Usually singletons are used for centralized management of internal or external resources and they provide a global point of access to themselves. ? The singleton pattern is one of the simplest design patterns: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. In this case the same instance can be used from everywhere, being impossible to invoke directly the constructor each time.
  • 19. 1st Way ? class Singleton ? { ? private static Singleton instance; ? private Singleton() { } ? public static synchronized Singleton getInstance() ? { ? if (instance == null) ? instance = new Singleton(); ? return instance; ? } ? public void doSomething() { } ? } 2nd Way ? class Singleton ? { ? private static Singleton instance = new Singleton(); ? private Singleton() ? { ? ... ? } ? public static synchronized Singleton getInstance() ? { ? return instance; ? } ? public void doSomething() ? { ? ... ? } ? }
  • 20. Factory Pattern ? When a interface does not know which sub-class of objects initilize it
  • 23. Adapter Design Pattern ? The adapter pattern is adapting between classes and objects. Like any adapter in the real world it is used to be an interface, a bridge between two objects. ? it's used to identifying a simple way to realize relationships between entities. ? The main use of this pattern is when a class that you need to use doesn't meet the requirements of an interface.
  • 25. Composite Design Pattern ? Composite pattern is used where we need to treat a group of objects in similar way as a single object. Composite pattern composes objects in term of a tree structure to represent part as well as whole hierarchy ? This pattern creates a class contains group of its own objects. This class provides ways to modify its group of same objects
  • 28. Observer Design Pattern Observer pattern is one of the behavioral design pattern Observer design pattern is useful when you are interested in the state of an object and want to get notified whenever there is any change In observer pattern, the object that watch on the state of another object are called Observer and the object that is being watched is called Subject