Provider Pattern
practices
MINH NGUYEN
@LINKNODE SEPTEMBER, 2015
Object-Oriented Programming
23 Design Patterns5 Principles
Single responsibility
Open/closed
Liskov substitution
Integrated segregation
Dependency inversion
Software Architecture
3-tier
MVC
MVP
MVVM
….
Open-closed principle
“Software modules should be closed for modifications but open for extensions.”
Sample use case:
Requirements: VentusAR needs to supply a new model type: SolarPanel
Current action: Have to modify all existing code everywhere to support this new type
string message= “”;
if (type = “Wind”)
{
message = “Turbine is spinning”;
}
else if (type = “SolarPanel”)
{
message = “Solar panel is under the sun”;
}
else if ….
else if ….
else if ….
Violate Open-closed principle
(having to modify existing code to be able to add new feature)
Inspired by Factory Pattern
VentusModel
+ getMessage()
Turbine
+ getMessage()
SolarPanel
+ getMessage()
Transmission
+ getMessage()
VentusModelFactory
+ getInstant(name)
creates
Client
asks
products
Provider Pattern (Microsoft 2002)
* Mimic Plug-in/ Add-on architecture
* Do not have to modify existing code
* Just supply additional separate class
* Configure from external settings (config file, database,)
Create instant from string
+ External Settings
Provider pattern
From XML:
From Database:
string
string
* Supply a new Transmission model to the app without modifying code
Demo
Provider Pattern vs Factory Pattern ?
* In-code config
* Still have to modify existing code
* Configure easily from external settings (using .Net Reflection)
* Do not have to modify existing code
Q&A

Provider pattern practices

  • 1.
  • 2.
    Object-Oriented Programming 23 DesignPatterns5 Principles Single responsibility Open/closed Liskov substitution Integrated segregation Dependency inversion Software Architecture 3-tier MVC MVP MVVM ….
  • 3.
    Open-closed principle “Software modulesshould be closed for modifications but open for extensions.” Sample use case: Requirements: VentusAR needs to supply a new model type: SolarPanel Current action: Have to modify all existing code everywhere to support this new type string message= “”; if (type = “Wind”) { message = “Turbine is spinning”; } else if (type = “SolarPanel”) { message = “Solar panel is under the sun”; } else if …. else if …. else if …. Violate Open-closed principle (having to modify existing code to be able to add new feature)
  • 4.
    Inspired by FactoryPattern VentusModel + getMessage() Turbine + getMessage() SolarPanel + getMessage() Transmission + getMessage() VentusModelFactory + getInstant(name) creates Client asks products
  • 5.
    Provider Pattern (Microsoft2002) * Mimic Plug-in/ Add-on architecture * Do not have to modify existing code * Just supply additional separate class * Configure from external settings (config file, database,) Create instant from string
  • 6.
    + External Settings Providerpattern From XML: From Database: string string
  • 7.
    * Supply anew Transmission model to the app without modifying code Demo
  • 8.
    Provider Pattern vsFactory Pattern ? * In-code config * Still have to modify existing code * Configure easily from external settings (using .Net Reflection) * Do not have to modify existing code
  • 9.