1

Cannot link the example to the title, so here it is: Python strategy design pattern example

  • Unfortunately, Stack Overflow is not a tutorial service. Please review [ask], as well as check out the [help/on-topic] to see which topics are OK to ask about here. – user3483203 Jun 09 '18 at 18:16
  • 1
    `Strategy` is *not* a metaclass. They only use a metaclass there to mark `Strategy` as an *abstract* class, but that could be removed without much problems. – Willem Van Onsem Jun 09 '18 at 18:18

1 Answers1

1

First let's look at the basic idea of Strategy Pattern. What it really says is developing some algorithm (function/method/code fragment) which can be switched at run time.

If we are using an OOP supported language (Java, Python), most of the time, we can implement the Strategy pattern with the use of run time polymorphism. In your example also it shows how to achieve this exactly in that way.

No need to get confused with the notion of meta class. It's a python specific terminology, which is used to define the class object of Python. This one is a good answer, if you want to know more about meta classes in python.

And in your example, the notion of meta class doesn't quite related with Strategy pattern implementation. It was just used to mark the Strategy class there as an abstract class. You can develop your program even without that part. And it doesn't do any harm to the idea of Strategy pattern implementation.

Supun Wijerathne
  • 11,964
  • 10
  • 61
  • 87