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
209
votes
19 answers

What is the difference between the template method and the strategy patterns?

Can someone please explain to me what is the difference between the template method pattern and the strategy pattern is? As far as I can tell they are 99% the same - the only difference being that the template method pattern has an abstract class as…
Calanus
  • 25,619
  • 25
  • 85
  • 120
58
votes
6 answers

Inheriting methods' docstrings in Python

I have an OO hierarchy with docstrings that take as much maintenance as the code itself. E.g., class Swallow(object): def airspeed(self): """Returns the airspeed (unladen)""" raise NotImplementedError class…
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
17
votes
3 answers

template method pattern - naming conventions

I have this abstract class named as RenderableEntity . I have a public method render() that has some logic wrapped around abstract protected render() method. How should I name this abstract render() method. Is there some kind of convention eg.…
jellyfication
  • 1,595
  • 1
  • 16
  • 37
16
votes
3 answers

Differences between builder pattern and template method (builder vs template)

Template pattern provides algorithm in the base class whose steps can be modified in the derived class. In Builder pattern, concrete builder exposes methods for building a product which are called from the Director class. I understand there is…
Sandeep G B
  • 3,957
  • 4
  • 26
  • 43
15
votes
1 answer

Why does GoF advise using protected (as opposed to private) virtual methods in a C++ Template Method Pattern implementation?

From Gang of Four on the Template Method Pattern: Three implementation issues are worth noting: Using C++ access control. In C++, the primitive operations that a template method calls can be declared protected members. This ensures that they…
Paul Caheny
  • 1,281
  • 3
  • 11
  • 16
15
votes
2 answers

what's the difference between the patterns Strategy, Visitor and Template Method?

I'm in a class where we just learned about these design patterns. However I couldn't see any difference between them. They sound just like the same, creating concrete classes over the abstract one. Could somebody help me kill this doubt? thanks (:
11
votes
9 answers

Where should we use Template Method - pattern?

Can anyone let me know some example situations where Template Method - pattern should be used? Give me some real-world use from your own experience. (I have so far found it useful only for mapping data in the DA layer. Sorry!!!)
user366312
  • 16,949
  • 65
  • 235
  • 452
10
votes
2 answers

C++: Difference between NVI and Template Method Patterns?

What is the difference between NVI ( Non-Virtual Interface ) and the Template Method patterns? They seem very similar and I've read both that they're basically the same and that they're subtly different with Template being somehow more general.
8
votes
2 answers

Template Method and Strategy design patterns

This is probably a newbie question since I'm new to design patterns but I was looking at the Template Method and Strategy DP's and they seem very similar. I can read the definitions, examine the UML's and check out code examples but to me it seem…
8
votes
3 answers

Objective-C - Template methods pattern?

So I've been reading about template methods on Objective-C and I am trying to understand what's so special about them. From my understanding any method in a Base class can be over-ridden and super can be called? So is a template method anything more…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
8
votes
5 answers

What's the simplest way to satisfy a pure abstract method with methods from other base classes

Edit: Per some comments, by simple I mean a) less code, b) easy to maintain, and c) hard to get wrong. Edit #2: Also, using containment instead of private inheritance is not objectionable if it does indeed simplify the implementation of…
8
votes
3 answers

Python naming conventions for attributes and methods meant to be overwritten

I have some object oriented code in Python, where some classes are meant to be extended to provide the missing custom bits of code (a la Template Method pattern, but also with variables), that will only be used by the super class, not by the client…
fortran
  • 74,053
  • 25
  • 135
  • 175
8
votes
1 answer

typedef inheritance from a pure abstract base

Edit: Found duplicate I've whittled down some problem code to the simplest working case to illustrate the following: my typedef in a pure abstract base class is not being inherited by the derived class. In the code below I'd like to inherit the…
Shamster
  • 2,092
  • 5
  • 24
  • 27
7
votes
1 answer

What does template mean as a suffix of a class name?

In many programs, a Class with the suffix Template exists. For example, org.springframework.web.client.RestTemplate, etc. What does template mean as a class name suffix? Does it mean the Template Method pattern? Do you know the reason? Have a good…
7
votes
1 answer

Does the "android activity lifecycle" use the Template Method pattern?

I believe the Template method pattern involves encapsulating each step in the algorithm. I think activity's life cycles (onCreate, onResume, etc) are steps that must be overridden by the concrete class. Does this mean that the Android activity…
ShakeJ
  • 633
  • 5
  • 10
1
2 3 4 5 6 7 8