Typescript Design Patterns: Template Method Design Pattern

preview_player
Показать описание
In this video you will learn about one of the most popular Software Design Patterns. "The Template Design Pattern" written in Typescript. You will get an understanding of what it is and how to use it. For more content like this, please support me by giving me a like and subscribe!

if you have any questions or comments please feel free to comment below!

#typescript #designPatterns #templateMethod
Рекомендации по теме
Комментарии
Автор

What you have described here is not exactly the Template Method Pattern.
You've described OOP 101 or more specifically, polymorphism.

The Template Method Pattern relies on OOP and the concepts you've described, but it is more specific.

Most importantly, it is a behavioral pattern, not a structural or state pattern, which is what classes and subclasses more often address.

Let's say, for example, you want to write a template method for handling HTTP Requests because, except for some specific cases, most of the work is the same (receive the request, parse the body, extract parameters, etc)

You would indeed define an abstract base (a.k.a. super) class with a method like "handleRequest".

In the superclass implementation, you might have some common stuff, like logging that a request was received from some certain remote host at some certain time and then calls to a number of other methods that subclasses are expected to implement. The idea is to control the *flow* of the handler with the details delegated to subclasses.

To do this in a more or purely functional way might require defining a main function that takes a set of functions, then passing the specific implementations of some of the main function's algorithm (steps) to the main function before it is invoked.
I honestly haven't worked that out.

I'm not leaving this comment to be overly critical, just trying to be helpful. I think the JavaScript community may be less aware of some of the proven techniques and patterns that have been common in the Java and C++ communities since the 1990s. Sometimes, those patterns do not make sense in the JavaScript paradigm or there are idiomatic solutions that should be used instead.




Please keep making videos and studying computer science. Good luck and may all your variables be defined and !== null.

scottbockelman
Автор

can you overload the methods in the template in each class?

youmnaification