SlideShare une entreprise Scribd logo
1  sur  12
Template Method Pattern ~ Mother of all frameworks ~ Srikanth P Shreenivas [email_address] http://www.srikanthps.com
Game Console for playing Pool Slide    public class Pool { aTypicalGamingSession() { startup(); retrieveLastSavedState(); displayPoolTable(); while (not exit) {   acceptUserInput();   redrawTheTable(); } printWinner() saveUserScore; updateHighScores; } }
Game Console – More games Slide    ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Game Console – What’s common?  Slide    ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Game startGame() { retrieveLastSavedState(); displayGame(); while (not exit) { reactToUserControl(); } saveGame(); printWinner(); } Abstract displayGame(); Abstract reactToUserControl(); Delegate game specific behavior to derived classes, while controlling the main game behavior in base class. Common Behavior Game-specific Behavior Chess displayGame() { displayChessBoard(); } reactToUserControl() { moveThePiece(); } Pool displayGame() { displayPoolTable(); } reactToUserControl() { strikeWithCueBall(); }
Template Method Pattern Slide    ,[object Object],[object Object],[object Object],[object Object],[object Object],ConcreteClass 2 step1() { } step3OptionalStep() { //diff. implementation } Algorithm() { step1(); step2MustAlwaysDoThis(); step3OptionalStep(); step4finalStep(); } Abstract step1(); Final step2MustAlwaysDoThis() { } step3OptionalStep() { //Default code } Final step4FinalStep() { } Base Class ConcreteClass 1 step1() { }
Inversion of control ,[object Object],[object Object],Slide    Hollywood Principle ,[object Object],[object Object],[object Object],[object Object]
Servlets – A case study for IoC ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide
Servlets – IoC and Template Method Pattern ,[object Object],[object Object],[object Object],[object Object],Slide    Servlet Container’s Hollywood Principle: Don’t call me, I will call you (servlet) !!!  (whenever I hear from a browser) Servlet’s Template Method: Let me have the control of algorithm and let me deal with HTTP, you (Developer) just respond with some meaningful action when I call your methods.
“ Mother of all frameworks”….How? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Slide
Ways of Extending Classes  (and Frameworks) ,[object Object],[object Object],[object Object],[object Object],Slide
Example of Strategy Pattern Slide    Use Strategy to plug-in a different implementation. CRT print() { print on console’s monitor } PaperPrinter print() { printOnLaserPrinter(); } Game void startGame() { … printer.printWinner(); … } Printer printer; Printer print()
Thanks

Contenu connexe

Tendances

Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
Todor Kolev
 
Mocking in Java with Mockito
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with Mockito
Richard Paul
 

Tendances (20)

Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Design Pattern:: Template Method
Design Pattern:: Template MethodDesign Pattern:: Template Method
Design Pattern:: Template Method
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
 
Learning php 7
Learning php 7Learning php 7
Learning php 7
 
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
 
M C6java6
M C6java6M C6java6
M C6java6
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
C++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing FrameworkC++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing Framework
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
 
Mocking in Java with Mockito
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with Mockito
 
How to test models using php unit testing framework?
How to test models using php unit testing framework?How to test models using php unit testing framework?
How to test models using php unit testing framework?
 
Control statements in java programmng
Control statements in java programmngControl statements in java programmng
Control statements in java programmng
 
Unit Testing with Python
Unit Testing with PythonUnit Testing with Python
Unit Testing with Python
 
Java control flow statements
Java control flow statementsJava control flow statements
Java control flow statements
 

En vedette

Design Patterns
Design PatternsDesign Patterns
Design Patterns
soms_1
 
Adapter Pattern Abhijit Hiremagalur 200603
Adapter Pattern Abhijit Hiremagalur 200603Adapter Pattern Abhijit Hiremagalur 200603
Adapter Pattern Abhijit Hiremagalur 200603
melbournepatterns
 
Padroes Template-Method (Método Gabarito)
Padroes Template-Method (Método Gabarito)Padroes Template-Method (Método Gabarito)
Padroes Template-Method (Método Gabarito)
Eduardo Mendes
 
Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材
teddysoft
 

En vedette (20)

Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
The benefits of erp products
The benefits of erp productsThe benefits of erp products
The benefits of erp products
 
dezainn
dezainndezainn
dezainn
 
常見設計模式介紹
常見設計模式介紹常見設計模式介紹
常見設計模式介紹
 
2016.8.1 Design Pattern Eric
2016.8.1 Design Pattern Eric2016.8.1 Design Pattern Eric
2016.8.1 Design Pattern Eric
 
The Decorator Pattern
The Decorator PatternThe Decorator Pattern
The Decorator Pattern
 
Proxy Design Pattern
Proxy Design PatternProxy Design Pattern
Proxy Design Pattern
 
Design Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator PatternDesign Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator Pattern
 
覚えて帰ろうJavaデザインパターン
覚えて帰ろうJavaデザインパターン覚えて帰ろうJavaデザインパターン
覚えて帰ろうJavaデザインパターン
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Adapter Pattern Abhijit Hiremagalur 200603
Adapter Pattern Abhijit Hiremagalur 200603Adapter Pattern Abhijit Hiremagalur 200603
Adapter Pattern Abhijit Hiremagalur 200603
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
デザインパターン
デザインパターンデザインパターン
デザインパターン
 
Padroes Template-Method (Método Gabarito)
Padroes Template-Method (Método Gabarito)Padroes Template-Method (Método Gabarito)
Padroes Template-Method (Método Gabarito)
 
Crystalを触り始めてから起こったこと
Crystalを触り始めてから起こったことCrystalを触り始めてから起こったこと
Crystalを触り始めてから起こったこと
 
Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 

Similaire à Template Method Design Pattern

Graphics, Threads and HTTPConnections in MIDLets
Graphics, Threads and HTTPConnections in MIDLetsGraphics, Threads and HTTPConnections in MIDLets
Graphics, Threads and HTTPConnections in MIDLets
Jussi Pohjolainen
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Robot Media
 

Similaire à Template Method Design Pattern (20)

Lesson12 other behavioural patterns
Lesson12 other behavioural patternsLesson12 other behavioural patterns
Lesson12 other behavioural patterns
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features Summary
 
Os Secoske
Os SecoskeOs Secoske
Os Secoske
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agents
 
Graphics, Threads and HTTPConnections in MIDLets
Graphics, Threads and HTTPConnections in MIDLetsGraphics, Threads and HTTPConnections in MIDLets
Graphics, Threads and HTTPConnections in MIDLets
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
Testing basics for developers
Testing basics for developersTesting basics for developers
Testing basics for developers
 
Hands on clang-format
Hands on clang-formatHands on clang-format
Hands on clang-format
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transforms
 
Ppt on java basics
Ppt on java basicsPpt on java basics
Ppt on java basics
 
unit-3java.pptx
unit-3java.pptxunit-3java.pptx
unit-3java.pptx
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
svelte-en.pdf
svelte-en.pdfsvelte-en.pdf
svelte-en.pdf
 
GWT Extreme!
GWT Extreme!GWT Extreme!
GWT Extreme!
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
 
Core java
Core javaCore java
Core java
 
Thymeleaf and Spring Controllers.ppt
Thymeleaf and Spring Controllers.pptThymeleaf and Spring Controllers.ppt
Thymeleaf and Spring Controllers.ppt
 
Charla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo WebCharla EHU Noviembre 2014 - Desarrollo Web
Charla EHU Noviembre 2014 - Desarrollo Web
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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)
 
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
 
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?
 
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...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 

Template Method Design Pattern

  • 1. Template Method Pattern ~ Mother of all frameworks ~ Srikanth P Shreenivas [email_address] http://www.srikanthps.com
  • 2. Game Console for playing Pool Slide public class Pool { aTypicalGamingSession() { startup(); retrieveLastSavedState(); displayPoolTable(); while (not exit) { acceptUserInput(); redrawTheTable(); } printWinner() saveUserScore; updateHighScores; } }
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. Example of Strategy Pattern Slide Use Strategy to plug-in a different implementation. CRT print() { print on console’s monitor } PaperPrinter print() { printOnLaserPrinter(); } Game void startGame() { … printer.printWinner(); … } Printer printer; Printer print()