⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strategyexample.java

📁 Java Pattern Oriented Framework (Jt) 是为了实现Java快速开发的面向模式的框架。
💻 JAVA
字号:


package Jt.examples.patterns;

import Jt.JtFactory;
import Jt.JtMessage;
import Jt.JtObject;
import Jt.JtStrategy;
import Jt.examples.HelloWorld;
import Jt.xml.JtXMLHelper;


/**
 * Example of the use of JtStrategy.
 */

public class StrategyExample  {



  public StrategyExample () {
  }


  /**
   * Demonstrates the use of JtStrategy. It encodes
   * an object using two XML strategies.
   */

  public static void main(String[] args) {

    JtFactory factory = new JtFactory ();
    JtStrategy strategy;
    JtObject concreteStrategy;
    JtMessage msg;
    HelloWorld hello = new HelloWorld ();
    
    hello.setGreetingMessage("Hello World ...");

    // Create an instance of JtStrategy

    strategy = (JtStrategy) factory.createObject (JtStrategy.JtCLASS_NAME, "strategy");

    // Specify the concrete strategy to be executed.

    concreteStrategy = (JtObject) factory.createObject (JtXMLHelper.JtCLASS_NAME, "concreteStrategy");
    strategy.setConcreteStrategy(concreteStrategy);

    // Encode the object using the XML strategy selected
    
    msg = new JtMessage (JtObject.JtXML_ENCODE); 
    msg.setMsgContent(hello);
    System.out.println ("Java encoding:" +  factory.sendMessage (strategy, msg));
    
    // Use a different encoding strategy
    
    strategy.setConcreteStrategy(new JtObject ());
    
    System.out.println ("Jt encoding:" + factory.sendMessage (strategy, msg));
    
    factory.removeObject ("strategy");


  }

}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -