類 設計pattery策略我想用PHP來實現戰略設計模式: interface dummy_function {
public function render();
}
class a implements dummy_function {
public function render() {
echo "class a\n";
// I want
我有一個問題實施策略模式到我的項目。我創建了所有需要的文件,但是我在主要的新調用中遇到錯誤,因爲我似乎無法將策略初始化爲我想要的。 Strategy.h /*All the classes that implement a concrete strategy should use this
The AI class will use this file as a concrete strateg
我目前正在學習設計模式。在研究策略模式時,我發現了一些對我來說很陌生的事情。我尋找關於這種模式的討論,但沒有人回答我的問題......我如何實施戰略模式,讓它變得乾淨,保持封裝並使添加新戰略變得容易。在這裏解釋一下我的問題是,「規範」的戰略格局: public interface Strategy {
public void run();
}
public class stratC
給定一個典型的戰略格局 class Strategy
{
public:
virtual int execute() const = 0;
}
class StrategyA : public Strategy
{
public:
int execute() const override;
}
class StrategyB : public Strateg
我正在爲我的項目使用簡單的策略模式。 我需要在某些枚舉中添加每個具體的策略接口類以供將來使用。爲了方便起見,我使用了一個臨時接口,應該在稍後進行替換,而不是實現每個具體的類來完成第一個設計。 這裏是簡單的代碼,我試過了。 public interface Strategy{
public void execute();
}
public interface NeedToImplem