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

泪湿孤枕 提交于 2020-01-06 01:36:54
问题 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 example, he might want to insert some logging at specific points in the operation, or he might want to modify the object at a certain point. I see 2 ways of doing it: the template method pattern seems appropriate, but it will force me to add a lot of protected

Where should we use Template Method - pattern?

被刻印的时光 ゝ 提交于 2019-12-29 06:20:36
问题 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!!!) 回答1: I tried to give you some real-world examples, and some common situations where Template Method pattern should be used. When you want your program be "Open For Extension” and also “Closed for Modification”. This means that the behavior of the module can be

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

浪尽此生 提交于 2019-12-24 08:47:14
问题 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 template and the form from (1) needs to redisplayed, together with some error messages. Only some fields are common across the different forms. If there are no errors a result message needs to be mailed. For each form there is a result mail template. I

Why is JdbcTemplate an example of the Template method design pattern

我的梦境 提交于 2019-12-22 10:54:58
问题 I was reading about design patterns, in particular about the template method, when my attention was caught by this question on SO. After reading the explanation and specific code I am still wondering why this is an example of the 'Template method' design pattern. According to GoF, the intent of this pattern is: “Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the

Understanding Template method pattern

谁说我不能喝 提交于 2019-12-19 10:08:24
问题 From what I understand, Template method is nothing but ordinary method that calls virtual or abstract methods defined in child class. Am I right, or is there something else important about this pattern that I miss? abstract class Foo { public void IamTemplateMethod() { // which will be called in child class object method1(); // because this... method2(); // ...or this method was called in me } public virtual void method1() { ... } // to be overriden in child class public abstract void method2

Is Factory method pattern a specialized case of Template method pattern?

给你一囗甜甜゛ 提交于 2019-12-13 03:38:52
问题 GOF talks about frameworks for "Factory method" pattern. Frameworks need objects but implementation of objects depends upon application hence an abstract method to create the object is created. Also as return type is needed so interface for the object needed is defined, it defines the apis needed for the object. Actual objects are created by subclasses (concrete Application) . This is a creational pattern. For Template pattern the only change is that the encapsulating class does not know the

typedef inheritance from a pure abstract base

ぃ、小莉子 提交于 2019-12-12 07:55:44
问题 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 system_t typedef into the ConcreteTemplateMethod : #include <iostream> // pure abstract template-method template <typename T> // T == Analyzer<U> class TemplateMethod { public: typedef T system_t; virtual void fn (const system_t& t) const = 0; };

Template method pattern where each implementation requires different arguments?

徘徊边缘 提交于 2019-12-11 03:39:17
问题 I have a base abstract class that needs an algorithm for Authentication. I have two implementations of this, one will hash a password and compare it to a stored hash, the other will use windows active directory. But before actually doing the hash check or the windows authentication, I have extra workflow logic that must absolutely be implemented. So things like failedPasswordCount, lastAuthenticationAttemptDate, IsUserApproved, etc. must always be modified or used in the same way no matter

Refactoring class design to convey the design intention

久未见 提交于 2019-12-11 03:22:54
问题 I have following class design. The complete code is available in " How to achieve this functionality using Generics? ". The code works fine and resolves the casting issue mentioned in " Refactoring Code to avoid Type Casting " In the RetailInvestmentReturnCalculator class, the GetInvestmentProfit() method utilizes CalculateBaseProfit() method present in InvestmentReturnCalculator abstract base class. This fact is not evident from the class design. QUESTION How to refactor this class design to

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

最后都变了- 提交于 2019-12-08 15:11:27
问题 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 difference with respect to the purpose of using these patterns. Template pattern is a behavioral pattern which changes one or more steps in a template whereas builder pattern is a Creational pattern. Apart from the above said difference, are there any