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

Factory method pattern and abstract factory pattern

I have a question which has been explained in many ways , but still has not made me clear. What is creating of objects by "Object composition" in terms of abstract factory pattern ? It seems like both the patterns use inheritance to create…
Chandan
  • 1,486
  • 2
  • 15
  • 24
2
votes
2 answers

How to apply Template Method Pattern for functions with different signatures?

How does one provide a unified interface to sets of functions, that are used in the same way? To illustrate, please look at the set of given library functions: /* existing library functions */ /* the signatures are different: some return int, some…
Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
2
votes
2 answers

Template method invocation order in python

What would be the simplest way to unit-test run function? Here I'm not interested in what fun* functions do, but only if the order of their invocation is correct. from mock import Mock (many, arguments, four, fun) = ('many', 'arguments', 'four',…
LavaScornedOven
  • 737
  • 1
  • 11
  • 23
1
vote
1 answer

testing template method using mocking framework; isn`t it low level

Suppose I have a template method template() which calls m1() and m2(). I have tests for m1 and m2. Now while testing template() should one use mocking to check if m1 and m2 were correctly called or test its API or both. I feel testing to check the…
Susanta
  • 319
  • 2
  • 11
1
vote
2 answers

What design pattern is this - Adapter, Provider, Delegate, Template Methods, or ...?

Here's a simple design patterns question: As part of my current project, I have written an interface that performs a database search (using webservices and relevant client stubs) and returns the results - which will be used subsequently by a struts…
Ashkan Aryan
  • 3,504
  • 4
  • 30
  • 44
1
vote
0 answers

Child classes common method in Template Method design pattern

I have to implement a solution where the code behaves differently according to different conditions. I created some pseudocode to show it: public void generalMethod() { firstMethod(); secondMethod(); commonMethod(); } public void…
1
vote
0 answers

Python : using import * at local scope

I'm tring to use factory pattern (or factory method pattern) for image analysis. But memory and harddisk restriction keeps me to reduce any of dependencies as much as possible or make them as soft-dependencies. And I encountered SyntaxError by…
1
vote
0 answers

Template Method pattern testing with Java JUnit

I am writing template method pattern for Sorting (SelectionSort, InsertionSort and QuickSort). I wrote SelectionSort interface, following by its implementation (SelectionSortImpl) and then its unit tests with JUnit (SelectionSortImplTest). As a next…
maz
  • 11
  • 2
1
vote
1 answer

Classes with template method design

I have made this four classes and I'm wondering if I used the template method design pattern correctly because I'm really struggeling with this subject. I have used the methods getPrijsBehandeling() and getBeschrijvingBehandeling() as my abstract…
1
vote
1 answer

Can I create my own methods in a subclass using the template method design pattern?

Whether using methods created outside the abstract class will disturb the Template Method design pattern? Will it still be Template Method pattern if I create MyOwnMethod and call it inside a method? public abstract class TemplateMethodClass { …
1
vote
2 answers

Observer with full transparency

I'm implementing observer pattern in the following way: interface Layer{ void adjustString(Set strings); } interface NotifiableLayer extends Layer{ void layerAdjusted(Layer layer); } abstract class ObservableLayer implements…
1
vote
1 answer

Template Method: How to use it when you want to be able to flexibly change primitive options?

The problem is best explained with the following code: public class TemplateClass { public void templateOne() { checkConditionA(); primitiveOp1(); checkConditionB(); } public void templateTwo() { …
1
vote
1 answer

Object's state in the Template method design pattern

Here is an implementation example of the algorigthm in the base absctract class from http://sourcemaking.com/design_patterns/template_method/php public final function showBookTitleInfo($book_in) { $title = $book_in->getTitle(); $author =…
BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
1
vote
1 answer

Inheritance: main method in parent class with relation to specific implementation of a few methods in child

I need to implement two similar processes which basicaly do the same logic but a few parameters/methods may differ. I'm wondering if it would be a good practice to extract the main logic to a parent class and specify a result of a few methods to…
adolzi
  • 671
  • 2
  • 7
  • 15
1
vote
1 answer

Use Ada's My_Class'Class(This) cast to mimic template method design pattern

Context I recently came into a basic OOP / Ada 2012 design issue. Basically, I have a parent class that realizes an interface contract. This is done in several steps inside an implementation provider (ConcreteX). A child class extends this…
LoneWanderer
  • 3,058
  • 1
  • 23
  • 41