Questions tagged [template-method-pattern]

The Template Method pattern is a design pattern that defines the program skeleton of an algorithm in a method, called a template method, which defers some steps to subclasses. It is one of the Gang of Four's behavioral design patterns.

This is one of the Gang of Four's behavioral , first published in Gamma et al.'s book "Design Patterns: Elements of Reusable Object-Oriented Software".

More information is available on Wikipedia.

120 questions
1
vote
0 answers

How can I use template-methods in groovy-servlet with out compile?

I have a groovy-servlet named query1_action.groovy as: String sql = "..."; String sql_count = "..."; try { def ctx = new javax.naming.InitialContext().lookup("java:/comp/env"); def datasource = ctx.lookup("jdbc/tlink"); def executer =…
xunitc
  • 207
  • 1
  • 2
  • 10
1
vote
2 answers

Calling static method from non-static method in Typescript

I have some static stuff in all my hierarchy (in this example, the _image). I would want to be able to access the correspondant _image without having to repeat the code: This would be great: class Actor { static _image; // I need it to be…
Alf Sanzo
  • 141
  • 2
  • 9
1
vote
1 answer

Design pattern for different input parameter type and data extraction algorithm

I am new to design pattern. My question is what pattern do I use in below case? interface UserExtractorService { String getUser(XXXX); default validate(File file); } class AExtractorService { public String getUser(String url) { …
punxism
  • 59
  • 1
  • 7
1
vote
3 answers

Using Template Method and Strategy together

Gang of Four sums up the difference between Template Method and Strategy as follows: Template methods use inheritance to vary part of an algorithm. Strategies use delegation to vary the entire algorithm. What are the scenarios where combining…
Siegmeyer
  • 4,312
  • 6
  • 26
  • 43
1
vote
0 answers

Cannot format data before calling the base class contructor in C#

I'm trying to implement the Template Method Pattern in C# to handle different behaviours between all the subclasses that inherit the TemplateFilter class. public abstract class TemplateFilter : Operand { public TemplateFilter(params…
1
vote
1 answer

Is the -Impl suffix a legitimate naming convention for a Hook method in Java?

I was going over some old code and found the following naming convention at a template method implementation. // TEMPLATE METHOD // Check condition and fail fast if condition is met. // Otherwise call the hook method (to be implemented by…
1
vote
4 answers

template method pattern and long parameter lists in c++

After the helpful answers to my last question I started using the template method pattern for a class with a lot of different options. Without having implemented them all, my current declarations for objects of that class now look like this: pc <…
Thomas
  • 1,001
  • 1
  • 10
  • 20
1
vote
2 answers

Java client/server application with 3 patterns

I am a college student, and I have to complete following task by the end of the month... I have to write a client/server application in java that implements 3 patterns: Hollywood principle, Facade pattern and Template method pattern... It must have…
1
vote
4 answers

private overrides of private methods pattern? (ANSWER: NVI)

What's the accepted jargon (if any) for describing methods meant to be invoked only virtually and from other methods in the base? I've occasionally seen this referred to as a callback, but that seems to stray pretty far from the original definition…
1
vote
2 answers

Rspec: How to properly test Template Method pattern?

Given two classes that use the template method design pattern: def Parent def all_params params.merge(extra_params) end def params {blah: "cool"} end def extra_params {} end end def Child < Parent def extra_params …
bigpotato
  • 26,262
  • 56
  • 178
  • 334
1
vote
1 answer

abstract class and Template Method pattern and HttpServlet

There is no any abstract methods in the HttpServlet which is declared abstract class with key word abstract. doGet and others are not abstract methods. So why HttpServlet is declared as abstract class without any abstract class? Is the HttpServlet…
1
vote
1 answer

Template Method calling super and use implementation

I have implemented Template Method, and i faced with this situation: public class ProductTemplate() { protected Item getItemFromShop(){ processItemPrice(); callOrderSummary(); } protected void processItemPrice()…
Vipercold
  • 599
  • 1
  • 7
  • 27
1
vote
2 answers

Template methode in threaded contexts

Let's say we have a template method that looks like this abstract class Worker { public void DoJob() { BeforJob() DoRealJob(); AfterJob(); } abstract void DoRealJob(); } subclasses that inherit from the Wroker classe should…
1
vote
2 answers

Providing dependencies to abstract classes

I was wondering if there is some best practice to provide dependencies to Abstract components. Lets say I have Template Method algorithm like this: public abstract class TemplateMethod { protected abstract void StepA(); …
1
vote
3 answers

Difference between Template Method (separation) and Strategy pattern?

My teacher is a really good one and I tend to understand his points, but this one just goes over my head. He explains Template Method in two variants; - Unification: the standard variant, that is composed of an abstract class with some abstract…