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
2 answers

Should I use events or the "template method" pattern for an open source library?

I am building an open source library that I can sum up to something like that: class SuperThing { public function doStuff($object) { // ... } } I want to offer the possibility to the user of the library to add custom behavior. For…
Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261
1
vote
1 answer

SRP applied to a workflow example: how to structure the classes in a sensible way

I have a problem with deciding about class responsibilities. I have 3 html-forms: For each form there is a html template containing some text and a marker for the form to be included Each form needs to be validated, if there is an error the…
1
vote
1 answer

Templated delegates

I have the following piece of code pattern: void M1(string s, string v) { try { // Do some work } catch(Exception ex) { // Encapsulate and rethrow exception } } The only difference is that the return type and the number and…
Addi
  • 291
  • 1
  • 6
  • 13
1
vote
3 answers

The meaning of `this` in JS template method pattern

Why does the marked line fail to find protectedACMember? var Module = (function (ns) { function AbstractClass() { this.protectedACMember = "abstract"; this.abstractPublicACMethod = function (input) { …
Queequeg
  • 2,824
  • 8
  • 39
  • 66
0
votes
1 answer

Implement a workchain with templatemethod pattern?

I have a hierarchy of worker classes, all of which do some kind of processing to a workpiece. The idea is, that each worker does some pre processing, pushes the workpiece to the subclass and then does some postprocessing: public void…
Jonathan
  • 2,698
  • 24
  • 37
0
votes
2 answers

Template Method vs Decorator Pattern

I write the code in Java and I have a case where I need to get the status of an order depending on the product type. Each product type has the same base logic as written below. protected String getStatus(ProductType productType, Result result) { …
CherryBelle
  • 1,302
  • 7
  • 26
  • 46
0
votes
0 answers

What design patter should I use for similar code for API connections?

I am currently using couple of classes in Python to connect to the API, process the information provided and put it in the database. Now, I need to do the same thing but for different API. In both cases I am dealing with the same data(apples and…
0
votes
0 answers

TemplateMethod pattern for REST API

I am trying to use TemplateMethod pattern for creating ServiceBaseClass which will be called from RESTAPI I am trying to create a wrapper API to call another API, another API will have around 50 endpoints Need for using TemplateMethod is to provide…
Sagar
  • 645
  • 2
  • 9
  • 31
0
votes
1 answer

Cannot use generic in abstract class

In my Spring Boot app, I am trying to implement Template Method and in my concrete class, I am trying to use generic as shown below: template interface: Not sure if I need to use it? public interface PDFGenerator { String createHtml(UUID…
user19540291
0
votes
0 answers

Duplicating current service or using Template Method (Design Pattern) in Java?

In my Java (Spring Boot) app, I have the following pdf service that uses BrandService: Service: public interface PDFService { String generatePdf(UUID uuid); } BrandServiceImpl: @Service @RequiredArgsConstructor public class…
user19254373
0
votes
0 answers

Template method pattern application

I have implemented the template method design pattern to handle the generation of different types of emails in this way: public abstract class TemplateBuilder { public buildEmail(Map emailObjects) { // do…
FrMan
  • 31
  • 8
0
votes
1 answer

Using Template Method (Design Pattern) for differentiate fields

I have been using a Create Request as shown below and needed to implement an Update Request with some fields non-required. @Data public class CreateRequest extends BaseRequest { @NotEmpty private String token; @NotEmpty private…
user18952345
0
votes
0 answers

template method design pattern - how to save and feed information into next step

I have an interface RequestProcessorInterface. There are different scenarios for processing a json request e.g. async vs synchronous request. I am trying to use template method pattern where the steps are like validate, preProcess, saveInDatabase,…
makcalif
  • 37
  • 7
0
votes
1 answer

Java AbstractQueuedSynchronizer and the template method pattern

While reading the source code of ReentrantLock, I found that internally it use a synchronizer which extends AbstractQueuedSynchronizer to control the lock. Doug Lea mentioned in this paper that AbstractQueuedSynchronizer serves as a "template method…
0
votes
1 answer

How to apply template method pattern in Python data science process while not knowing exactly the number of repeating steps

I like to apply the template method pattern for a data science project while I need to select or identify target subjects from a large pool of original subjects. I will create tags based on different characteristics of these subjects, i.e., age,…
KubiK888
  • 4,377
  • 14
  • 61
  • 115