Wednesday, 9 November 2011

Template Method Design Pattern

abstract class Fruit {
  
    // Is the implementation of a template method which will be used in all the subclasses.
    // This pattern is implemented by a Implementation Inheritance.
    public final void eat(){
        System.out.println("I am eating :" + this.getClass().getName());
    }
  
    abstract void cut();
}

class Apple extends Fruit{

    @Override
    void cut() {
        System.out.println("This is how we cut : " + this.getClass().getName());
    }
  
}

class Banana extends Fruit{

    @Override
    void cut() {
        System.out.println("This is how we cut : " + this.getClass().getName());
    }
  
}

public class TemplateMethodPattern {
    public static void main(String args[]){
        Fruit apple = new Apple();
        apple.eat();
        apple.cut();
        Fruit banana = new Banana();
        banana.eat();
        banana.cut();
    }
}

No comments:

Post a Comment

Using Handlebar Prompt in Semantic Kernal

> dotnet add package Microsoft.SemanticKernel.PromptTemplates.Handlebars --version 1.30.0 using Microsoft . SemanticKernel ; using Micr...