I have a set of operations that need to be executed as part of large process and subclasses may slightly differ part of the step. This problem seem to be solved by using the Template Method design pattern so I have something like below.
class BaseTemplate(object): def perform(self) self.disable() self.update() self.enable() def disable(self): # Generic behavior def update(self): # Generic behavior def enable(self) # Generic behavior class FooTemplate(BaseTemplate): def enable(self): # Foo-specific behavior def update(self): # Foo-specific behavior class BarTemplate(BaseTemplate): def update(self): # Bar-specific behavior
However, the problem with
update() is that the concrete templates just need to extra few step on top of what the base class did.
def update(): # Get X # Set field A of X # Set field B of X
def update(): # Get Y (Y is a subclass of X) # Set field A of Y # Set field B of Y # Set field C of Y (Field C is specific to Y which is a subclass of X)
The problem is that setting the field of
B are duplicated as shown above, so I could do something like this in
def update(): super(FooTemplate, self).update() # Handles fields A and B # Set field C
But calling super classes’ method in an overriding method is an anti-pattern Call Super
So, a different approach would be to have a no-op method that sets the field
C in the base class and then have template subclasses implement only when needed. However, this approach seem to violate OOP updating field
C is only required by
FooTemplate and other subclasses of
BaseTemplate should not know.
- Is it correct to use template method pattern for my usage?
- How to handle
update()which adds extra steps as templates go concrete in an OOP way?
- Any suggestions in general?
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!