You're about to create your best presentation ever

Blue Triangle Pattern Powerpoint Template

Create your presentation by reusing a template from our community or transition your PowerPoint deck into a visually compelling Prezi presentation.

Template Pattern Method

Transcript: (The Template Method Pattern) Coffee and Tea are running the show, they control the algorithm Code is duplicated across Coffee and Tea Code changes to the algorithm requires opening each subclass and making multiple changes Classes are organized in a structure that requires a lot of work to add a new caffeine beverage Knowledge of the algorithm and how to implement it is distributed over many classes Since steps 2 and 4 are somewhat similar, we can generalize it by calling step 2 "brew()" and step 3 "addCondiments()" and declare them as abstract also in the superclass while implementing them in their respective subclasses The recipes looks a lot like each other don't they? WT?! Template Method is sooooo easy man! Is that it? Let's play coding baristas and automate the process of making coffee and tea. public abstract class CaffeineBeverageWithHook { void prepareRecipe() { boilWater(); brew(); pourInCup(); if(customerWantsCondiments()) { addCondiments(); } } abstract void brew(); abstract void addCondiments(); void boilWater() { System.out.println("Boiling Water"); } void pourInCup() { System.out.println("Pouring into cup"); } boolean customerWantsCondiments() { return true; } } public class Coffee{ void prepareRecipe() { boilWater(); brewCoffeeGrinds(); pourInCup(); addSugarAndMilk(); } public void boilWater() { System.out.println("Boiling water"); } public void brewCoffeeGrinds() { System.out.println("Dripping coffee through filter"); } public void pourInCup() { System.out.println("Pouring into cup"); } public void addSugarAndMilk() { System.out.println("Adding sugar and milk"); } } Baristas! Please follow these recipes precisely when preparing Starbuzz beverages! public class Tea{ void prepareRecipe() { boilWater(); steepTeaBag(); pourInCup(); addLemon(); } public void boilWater() { System.out.println("Boiling water"); } public void steepTeaBag() { System.out.println("Steeping the tea"); } public void pourInCup() { System.out.println("Pouring into cup"); } public void addLemon() { System.out.println("Adding lemon"); } } Starbuzz Coffee Recipe: 1. Boil some water 2. Brew coffee in boiling water 3. Pour coffee in cup 4. Add sugar and milk Notice that both recipes follow the same algorithm: 1) Boil some water 2) Use hot water to extract coffee or tea 3) Pour the beverage into a cup 4) Add appropriate condiments to the beverage void prepareRecipe() { boilWater(); brew(); pourInCup(); addCondiments(); } Not quite! There are variations to the Template Method. Notice that our classes have redundant methods: 1) Boil some water 2) Brew coffee grinds/Steep tea bags 3) Pour the beverage into a cup 4) Add sugar & milk/Add lemon Template of the Template Method Note that by default, condiments are added to all beverages but us code baristas can edit customerWantsCondiments() in specific subclasses to, for example, make adding condiments optional to our customers abstract class AbstractClass { final void templateMethod() { primitiveOperation1(); primitiveOperation2(); concreteOperation(); } abstract void primitiveOperation1(); abstract void primitiveOperation2(); void concreteOperation() { //implementation } } The Template Method defines the steps of an algorithm and allows subclasses to provide the implementation for one or more steps. The Template Method provides a common "template" for an algorithm then lets subclasses redefine certain steps of that algorithm without changing its structure. Hooks are concrete methods that can be defined in template and basically does nothing by default. Subclasses are free to override them though if needed. For example... Starbuzz Tea Recipe: 1. Boil some water 2. Steep tea in boiling water 3. Pour tea in cup 4. Add lemon Hollywood principle enables subclasses to plug themselves into the system only through their main class. Higher-level components determine when they are needed and how. Subclasses does not call their own methods, they are invoked by the template defined in their main class. The End! We can still find a way to abstract the prepareRecipe() method! :) Now our implementation is a whole lot better but where does the Template Method come in? CaffeineBeverage class runs the show, it has the algorithm and protects it CaffeineBeverage class maximizes reuse among subclasses Algorithm can be found in one place and code changes only need to be made there Template method provides a framework that other subclasses can plug in to, new ones need only to implement few methods CaffeineBeverage class focuses on knowledge on algorithm and subclasses only completes the implementation Say what? Welcome to Coffee and Tea-Making Session (Java Style) Underpowered Tea & Coffee Implementation Let's make an abstract class and two subclasses, one for coffee and one for tea. The template method defines the steps of an algorithm and allows subclasses to provide the implementation for one or more steps. We can find a way to abstract the two processes to remove redundant methods! :) Starbuzz

powerpoint template

Transcript: Nobody knows babies like we do! Quality products . Good Customer service. Every Kid really loves this store.. BABYLOU ABOUT US About Us BabyLou was established in 2004. It has been more than a decade since we started, where we have ensured to take care of every need and want of every child and infant under one roof, true to the caption “NO BODY KNOWS BABIES LIKE WE DO”. Our benchmark is to provide 100% customer service and satisfaction and continue to deliver the same with a wide range of toys, garments and Baby Products. Play and Create We Are Best 01 02 03 Block games Building Blocks help Kids to use their brain. PLAY TO LEARN in Crusing Adventures Our Discoveries Enjoy a sunny vacation aboard a luxury yacht with the LEGO® Creator 3in1 31083 Cruising Adventures set. This ship has all the comforts you need, including a well-equipped cabin and a toilet. Sail away to a sunny bay and take the cool water scooter to the beach. Build a sandcastle, enjoy a picnic, go surfing or check out the cute sea creatures before you head back to the yacht for a spot of fishing. Escape into the mountains Disney Little Princes in Also available for your Babies..... Also... Out of The World… Our reponsibility BABYLOU…. Our Responsibility All children have the right to fun, creative and engaging play experiences. Play is essential because when children play, they learn. As a provider of play experiences, we must ensure that our behaviour and actions are responsible towards all children and towards our stakeholders, society and the environment. We are committed to continue earning the trust our stakeholders place in us, and we are always inspired by children to be the best we can be. Innovate for children We aim to inspire children through our unique playful learning experiences and to play an active role in making a global difference on product safety while being dedicated promoters of responsibility towards children.

Template Method Pattern

Transcript: "Don't call us, we'll call you" Allow low level components (the subclasses) to be hooked into the system, but higher level components decide when they are needed Reuse - shared code lies in the base class Algorithm changes done in one place New classes are easy to implement, clear what needs to be supplied Suited for frameworks, there is less rope for people to hang themselves with The template method defines steps of an algorithm in a base class, and defers to subclasses to provide the implementation of those steps Changing the algorithm leads to a myriad of new methods you need to implement in many places Difficult to see algorithm flow from a subclass. You need to see both class definitions to trace what code is being executed and when Each of the steps in the algorithm are defined as abstract (or virtual) methods Abstract are required steps Virtual are "hooks" that you can decide to implement if you want to Code Sample All of the steps in the algorithm are ideally protected methods that cannot be externally called, as they do not make sense on their own. Real world example - Attributes in MVC The "template" method is concrete and cannot be altered, ensuring that the steps inside the method are always called in the intended order (compare to a virtual base class method, where you could rewrite the entire method definition) Template Method Things to make your life easier when using this pattern: Don't have multiple levels of inheritance (true in general) Combine with composition where appropriate Downsides Fixed algorithm that you can't change at runtime (what if something else wants only part of your algorithm functionality?)

Now you can make any subject more engaging and memorable