
本文共 3244 字,大约阅读时间需要 10 分钟。
���������������Strategy Pattern���
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Context������������������������������������������������������������������������������������
���������������������������
������������������������������������
���������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������
���������������������
���������������������������
���������������������������������
package com.designPattern.strategy;public class StrategyTest { public static void main(String[] args) { // ������������������������ ContextGc a = new ContextGc(new GcA()); a.show(); // ������������������������ ContextGc b = new ContextGc(new GcB()); b.show(); // ������������������������ ContextGc c = new ContextGc(new GcC()); c.show(); }}interface GcStrategy { void algorithm();}class GcA implements GcStrategy { @Override public void algorithm() { System.out.println("������������������"); }}class GcB implements GcStrategy { @Override public void algorithm() { System.out.println("������������������"); }}class GcC implements GcStrategy { @Override public void algorithm() { System.out.println("������������������"); }}class ContextGc { private GcStrategy strategy; public ContextGc(GcStrategy strategy) { this.strategy = strategy; } public void show() { strategy.algorithm(); }}
������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
