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
0
votes
1 answer

Why is NeverSwitch class overriding my AlwaysSwitch class?

I am using the template method. I have a driver that was supplied to me that creates a Game and passes through one of two switching classes, AlwaysSwitch or NeverSwitch. The driver then creates a trial for Always Switch and a separate trial of…
user9170437
0
votes
2 answers

Template Method and Remove If Statements

So, Im studying Design Patterns, and Im studying the Template Method. From how I understood it, It is a set of Methods (The skeleton) wrapped in a Method (Operation) on an Abstract Class (If done via heritage), where different Concrete Subclasses…
Nickso
  • 785
  • 1
  • 10
  • 32
0
votes
1 answer

Does the ThreadPoolExecutor Apply the Template Pattern?

There are 2 hook methods in the ThreadPoolExecutor. This technique makes me think of the template method pattern, where there are hook methods in the abstract class. However, the hook methods in the abstract class of template method do differ from…
Rui
  • 3,454
  • 6
  • 37
  • 70
0
votes
1 answer

implementation of template method pattern in the real world scenario

I have requirement as below to build report building system. I should be able to create connection, where connection can be different database or same database. connection entity consist of connectionID,userName of the dabase, password I should be…
0
votes
0 answers

Convert fileSystem object to json and xml

I have created an arraylist with fileSystem using the Composite pattern. The file system has folders and files. The folder can also have folders. Using the template method, I need to create classes that convert a fileSystem object into two formats:…
0
votes
1 answer

Create a class method template, that will use function implemented later

Is it possible to implement such behaviour? It does not have to use inheritance, I just want to implement template method design pattern with generic arguments passing (with c++ templates). class A { public: template void…
omicronns
  • 357
  • 1
  • 10
0
votes
1 answer

Does empty method break the structure of template method pattern?

In template method pattern, we have a superclass which is defined abstract. And we have concrete classes that extend this class. Assume that we add a new function to template method and override it in some of subclasses(only for using in some…
0
votes
3 answers

What is the difference between Facade and Template Method Pattern in C#?

What is the difference between a Facade and a Template method pattern? Both of them provide high level views of the subsystem and hide it from the user. Facade Pattern internal class SubsystemA { internal string A1() { …
Lijin Durairaj
  • 4,910
  • 15
  • 52
  • 85
0
votes
1 answer

Separate logic from logging via template method pattern

May I use this template method pattern for separate logic from logging and exception handling or it is "bad practice"? For example I have this code: public abstract class Parent { private final Logger log =…
Sergey Frolov
  • 1,317
  • 1
  • 16
  • 30
0
votes
3 answers

Method only accessible from super-classes (C++ and other languages)

Suppose I have a super class that offers a public template method. Subclasses will have to implement some sub-operations. How do I declare this sub-ops to make sure they can only be called from SuperClass? There's protected, but that works the other…
Michael
  • 7,407
  • 8
  • 41
  • 84
0
votes
1 answer

How to design abstract listener and its implementation?

I have decided to split my application into 3 separate modules - one "abstract" with almost all application logic (anyone looking at the code can tell WHAT it does), one "implementation" module with all specific implementation layers (like db,…
user1071076
  • 157
  • 2
  • 9
0
votes
2 answers

Template method with return value

I have an outline for an algorithm - some logical steps that has to be performed in a specific order. The result of the algorithm has to be some number. Naturally this led me to the idea of using the template method pattern. This works fine for void…
Anton Sarov
  • 3,712
  • 3
  • 31
  • 48
0
votes
1 answer

Java template method pattern

I am trying to implement something along the lines of the template method pattern within some JavaEE beans that do some processing work on a dataset. Each processing bean takes the Job object, does some work then returns the updated job for the next…
DaveB
  • 2,953
  • 7
  • 38
  • 60
0
votes
3 answers

In C++, how does one access members of a derived class in base functions? (Is this even the correct practice?)

I am writing a physics program in C++ to approximate the range of an object using several algorithms. I have declared a base class Simulation which contains both concrete and abstract methods. (e.g. The function to approximate the range is pure…
Matthew
  • 65
  • 5
0
votes
1 answer

Testing template method design pattern implementation with PHPUnit Mock Objects

Suppose I have code with template method design pattern implementation. And I want to test sequence and counts of methods calls in my template method. I try to use PHPUnit mocks. My source code looks like this: class Foo { public function…
Ivan Velichko
  • 6,348
  • 6
  • 44
  • 90