jtdecorator.java

来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 96 行

JAVA
96
字号


package Jt;


/**
 * Jt Implementation of the Decorator design pattern.
 */

public class JtDecorator extends JtObject {

    public static final String JtCLASS_NAME = JtDecorator.class.getName(); 
    private static final long serialVersionUID = 1L;
    protected Object component = null;


    /**
     * Specifies the object that is being decorated (extra functionality added).
     * @param component component
     */

    public void setComponent (Object component) {
        this.component = component;
    }


    /**
     * Returns the object that is being decorated.
     */

    public Object getComponent () {
        return (component);
    }

    public JtDecorator () {
    }




    /**
     * Process object messages.
     * <ul>
     * <li>JtREMOVE - Performs any housekeeping that may be needed before the object is removed.
     * </ul>
     */

    public Object processMessage (Object msg) {

        String msgid = null;
        JtMessage e = (JtMessage) msg;

        if (e == null)
            return null;

        msgid = (String) e.getMsgId ();

        if (msgid == null)
            return null;


        if (msgid.equals (JtObject.JtREMOVE)) {
            return (null);     
        }

        return (super.processMessage(msg));


    }


    /**
     * Demonstrates the messages processed by JtDecorator.
     */

    public static void main(String[] args) {

        JtFactory factory = new JtFactory ();

        JtDecorator decorator;

        // Create JtDecorator

        decorator = (JtDecorator) factory.createObject (JtDecorator.JtCLASS_NAME, "decorator");

        //System.out.println (decorator);

        factory.removeObject (decorator);


    }

}


⌨️ 快捷键说明

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