SlideShare uma empresa Scribd logo
1 de 42
Baixar para ler offline
Requirements
MVP
View Controller
Model
Android framework
Activity
Fragment
…
How can I test easy ?
MVC(basic)
Manager
MVP
Manager
(Android component)
View Model
(business logic)
(POJO) (POJO)
Presenter
(middle man between view
and model)
Easy to test
MainActivity BeerProductItem
ServiceManager
MVP
MainActivityPresenter
MVP
PresenterInterface
MainActivity BeerProductItem
ServiceManager
MainActivityPresenter
ViewInterface
Base class
BaseMvpInterface.Presenter
BaseMvpActivity BaseMvpPresenter
BaseMvpInterface.View
Presenter getPresenter( );
V getView( );
void attachView( mvpView );
void detachView( );
void onViewCreate( );
void onViewDestroy( );
void onViewStart( );
void onViewStop( );
One Single responsibility
Presenter createPresenter( );
Int getLayoutView( );
void bindView( mvpView );
void setupInstance( );
void setupView( );
void initialize( );
void restoreView( savedInstanceState );
void onCreate( … );
void onRestoreInstanceState( … );
BaseMvpActivity
BaseMvpInterface.View
One Single responsibility
Presenter createPresenter( );
Void onRestoreInstanceState( … );
void onCreate( … );
void onCreateView( … );
void onViewCreated( … );
Int getLayoutView( );
void bindView( mvpView );
void setupInstance( );
void setupView( );
void initialize( );
void restoreView( savedInstanceState );
BaseMvpFragment
BaseMvpInterface.View
Template
BaseMvpInterface.Presenter
BaseMvpActivity BaseMvpPresenter
BaseMvpInterface.View
CustomActivity
<extend>
CustomPresenter
<extend>
CustomInterface.View
<extend>
CustomInterface.Presenter
<extend>
Adapter
BaseMvpInterfaceAdapter.Presenter
BaseMvpAdapter BaseMvpAdapterPresenter
BaseMvpAdapterInterface.View
Presenter getPresenter();
void notifyDataSetChanged();
void notifyItemInserted( int index );
void notifyItemRemoved( int index );
BaseMvpInterfaceAdapter.Presenter
BaseMvpAdapter BaseMvpAdapterPresenter
BaseMvpAdapterInterface.View
void setAdapter( A adapter );
A getAdapter();
int getItemViewType( int pos );
int getItemCount();
boolean hasItems();
List<BaseItem> getItems();
BaseItem getItem( int pos );
void setItems( List<BaseItem> items,
boolean isNextAvailable );
void addItem( BaseItem item );
void removeItem( int index );
void removeAllItems();
BaseMvpAdapterPresenter
@Override
public void addItem( BaseItem item ){
getPrivateItems( ).add( item );
getAdapter( ).notifyItemInserted( getItemCount() - 1 );
}
Example
public abstract class BaseViewHolder extends RecyclerView.ViewHolder{
public BaseViewHolder( ViewGroup parent, int layout ){
super( LayoutInflater
.from( parent.getContext() )
.inflate( layout, parent, false ) );
bindView( itemView );
}
public abstract void bindView( View view );
public Context getContext(){
return itemView.getContext();
}
}
BaseViewHolder
Example
public BeerProductHolder( ViewGroup viewGroup ){
super( viewGroup, R.layout.holder_beer_product );
}
@Override
public void bindView( View view ){
…
}
BeerProductHolder
public class BaseItem {
protected int type;
public BaseItem( int type ){
this.type = type;
}
public int getType(){
return type;
}
}
BaseItem
@Override
public int getItemCount(){
return getPresenter().getItemCount();
}
@Override
public int getItemViewType( int position ){
return getPresenter().getItemViewType( position );
}
@Override
public BaseViewHolder onCreateViewHolder( ViewGroup viewGroup, int viewType ){
switch( viewType ){
case TYPE_BEER_PRODUCT:
return new BeerProductHolder( viewGroup );
}
return null;
}
BeerAdapter
BaseItem
BeerProductItem
<extend>
Example
TYPE_BEER_PRODUCT
Load more
public interface OnLoadMoreListener{
void onLoadMore();
}
@Override
public VH onCreateViewHolder( ViewGroup parent, int viewType ){
if( viewType == BaseItemType.TYPE_PROGRESS ){
return (VH) new ProgressHolder( parent );
}
throw new RuntimeException( "View type not found: " + viewType );
}
@Override
public void onBindViewHolder( VH holder, int position ){
if( getItemViewType( position ) == BaseItemType.TYPE_PROGRESS ){
if( loadMoreListener != null ){
loadMoreListener.onLoadMore();
}
}
}
Load more
@Override
public void onBindViewHolder(
BaseViewHolder viewHolder, final int position ){
super.onBindViewHolder( viewHolder, position );
…
}
@Override
public BaseViewHolder onCreateViewHolder(
ViewGroup viewGroup, int viewType ){
…
return super.onCreateViewHolder( viewGroup, viewType );
}
Example
Template
BaseMvpAdapterInterface.Presenter
BaseMvpAdapter BaseMvpAdapterPresenter
BaseMvpAdapterInterface.View
CustomAdapter
<extend>
CustomAdapterPresenter
<extend>
CustomAdapterInterface.View
<extend>
CustomAdapterInterface.Presenter
<extend>
Converter
Normally
Raw
DataNetwork
If you want to custom?
Adapter
Converter
Network Adapter
Raw
Data Converter Adapter
Data
Response Body Adapter item
Easy to maintain
String id;
String name;
int price;
String id;
String name;
int price;
int amount = 1;
boolean isAdded = false;
Converter
Network Adapter
Raw
Data Converter Adapter
Data
BeerResult BeerItem
Easy to maintain
RxBus
MainActivity BeerFragment
ClearAddedButtonStateEvent
ClearAddedButtonStateAllEvent
AddBeerToCartEvent
RemoveBeerFromCartEvent
Test
Phase 1 Phase 2 Phase 3
Test must
done
Test must
done
MVP MVP
PresenterInterface
MainActivity BeerProductItem
ServiceManager
MainActivityPresenter
ViewInterface
Unit test
Activity/Fragment
PresenterInterface
MainActivity BeerProductItem
ServiceManager
MainActivityPresenter
CUT
MOCK
Unit test
MOCK
MOCK
Activity/Fragment
ViewInterface
PresenterInterface
BeerAdapter BeerAdapterPresenter
AdapterInterface
Unit test
Adapter
PresenterInterface
BeerAdapter
Unit test
Adapter
MOCK
CUT
AdapterInterface
BeerAdapterPresenter
PresenterInterface
MainActivity BeerProductItem
ServiceManager
MainActivityPresenter
CUT
ViewInterface
MOCK
Integration test
MOCK
MOCK
Activity/Fragment
PresenterInterface
MainActivity BeerProductItem
ServiceManager
MainActivityPresenter
CUT
ViewInterface
MOCK
Integration test
MOCK
CUT
Activity/Fragment
NongBeer MVP Demo application

Mais conteúdo relacionado

Mais procurados

Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
Wei Ru
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
Kai Koenig
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
Anh Quân
 

Mais procurados (20)

Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
 
Solid angular
Solid angularSolid angular
Solid angular
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
[2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿![2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿!
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)[2019] 벅스 5.0 (feat. Kotlin, Jetpack)
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Databinding and Performance-Tuning in Angular 2
Databinding and Performance-Tuning in Angular 2Databinding and Performance-Tuning in Angular 2
Databinding and Performance-Tuning in Angular 2
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injection
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SF
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
 
AngularJS Basic Training
AngularJS Basic TrainingAngularJS Basic Training
AngularJS Basic Training
 
I os 11
I os 11I os 11
I os 11
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2
 

Semelhante a NongBeer MVP Demo application

Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
Mahmoud Hamed Mahmoud
 
Apple Templates Considered Harmful
Apple Templates Considered HarmfulApple Templates Considered Harmful
Apple Templates Considered Harmful
Brian Gesiak
 

Semelhante a NongBeer MVP Demo application (20)

[22]Efficient and Testable MVVM pattern
[22]Efficient and Testable MVVM pattern[22]Efficient and Testable MVVM pattern
[22]Efficient and Testable MVVM pattern
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design Patterns
 
Fun with RecyclerView
Fun with RecyclerViewFun with RecyclerView
Fun with RecyclerView
 
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
 
Building a Native Camera Access Library - Part II.pdf
Building a Native Camera Access Library - Part II.pdfBuilding a Native Camera Access Library - Part II.pdf
Building a Native Camera Access Library - Part II.pdf
 
ButterKnife
ButterKnifeButterKnife
ButterKnife
 
Practical Protocol-Oriented-Programming
Practical Protocol-Oriented-ProgrammingPractical Protocol-Oriented-Programming
Practical Protocol-Oriented-Programming
 
Practialpop 160510130818
Practialpop 160510130818Practialpop 160510130818
Practialpop 160510130818
 
MCE^3 - Natasha Murashev - Practical Protocol-Oriented Programming in Swift
MCE^3 - Natasha Murashev - Practical Protocol-Oriented Programming in SwiftMCE^3 - Natasha Murashev - Practical Protocol-Oriented Programming in Swift
MCE^3 - Natasha Murashev - Practical Protocol-Oriented Programming in Swift
 
Vaadin DevDay 2017 - DI your UI
Vaadin DevDay 2017 - DI your UIVaadin DevDay 2017 - DI your UI
Vaadin DevDay 2017 - DI your UI
 
Building impressive layout systems with vaadin
Building impressive layout systems with vaadinBuilding impressive layout systems with vaadin
Building impressive layout systems with vaadin
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 
ASP.NET MVC Internals
ASP.NET MVC InternalsASP.NET MVC Internals
ASP.NET MVC Internals
 
Getting Started with Combine And SwiftUI
Getting Started with Combine And SwiftUIGetting Started with Combine And SwiftUI
Getting Started with Combine And SwiftUI
 
Net conf BG xamarin lecture
Net conf BG xamarin lectureNet conf BG xamarin lecture
Net conf BG xamarin lecture
 
SwiftUI and Combine All the Things
SwiftUI and Combine All the ThingsSwiftUI and Combine All the Things
SwiftUI and Combine All the Things
 
Apple Templates Considered Harmful
Apple Templates Considered HarmfulApple Templates Considered Harmful
Apple Templates Considered Harmful
 
Swift Delhi: Practical POP
Swift Delhi: Practical POPSwift Delhi: Practical POP
Swift Delhi: Practical POP
 
Rcp by example
Rcp by exampleRcp by example
Rcp by example
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
 

Último

Último (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

NongBeer MVP Demo application