mardi 17 novembre 2020

Require guidance for a low level design problem

I have a Main class. There are five strategies needs to be implemented from which customer can choose one strategy on run time. Here I am using strategy patterns because the objective of these is the same but the algorithm is different. Apart from common functions (defined in the interface of strategy classes), there could be some other functions as well in each strategy class to fulfil some requirements if one has chosen that particular strategy at runtime. Some requirements means extra methods which are required to fulfil the requirements but at same time it may or may not be required at user's end. Also, there are some common functions that I am defining in the Main class. Common means which could be helpful for any strategies.

class Main:
    def __init__(self, input):
        self.other_work = Extra(input)
        self.strategy = Factory(input)

Question 1: How to use this class:

a = Main(input)

# if want to use some extra function
a.other_work.do_this()

# if related to particular strategy
a.strategy.uncommonStrategy1()

Here challenges are:

  1. How can user know that this extra uncommonStrategy1 function is defined in Strategy1 class and not in Extra class.
  2. I can put uncommonStrategy1 function in Extra class as well but it is irrelevant to other strategies.

Aucun commentaire:

Enregistrer un commentaire