lundi 11 mars 2019

java Decorator: get component null

everyone.

I am making a game mod.And all questions are about this.

Firstly,since there are many modifications but almost they won't be intervened each other.I mean ,they are independent.

So which design pattern should I take?

I use Decorator now here.

Secondly,the next decorator get the null FilePath. I show my codes following.

Component

public abstract class Component {

public String FilePath;

public abstract String operation();}

ConcreteComponent

public class ConcreteComponent extends Component{

    public ConcreteComponent(String FilePath) {
        this.FilePath = FilePath;
        // TODO Auto-generated constructor stub
    }

Bugfix

public class bugfix extends Decorator {

    public bugfix(Component c) {
        // TODO Auto-generated constructor stub

        super(c);
    }
    public String operation()
    {
        String done = super.operation();

        //to do here
        return done + "bugfix";
    }

}

BankEnhanced

public class BankEnhanced extends Decorator{

    public BankEnhanced(Component c) {

        // TODO Auto-generated constructor stub
        super(c);
    }
    public String operation()
    {
        String done = super.operation();
        //todo here

        return done + "enhanced";
    }
}

main

        String strFilePath = txtFilePath.getText();

        Component c = new ConcreteComponent(strFilePath);

        Decorator d = new bugfix(c);

        if(chkBankEnhanced.isSelected())
        {               
            System.out.println("Enhanced");
            Decorator d = new BankEnhanced(d);

        }

        d.operation();

When checkbox chkBankEnhanced is selected, the c.FilePath it wrapped is turned to be null.

But in bugfix it works well.

What's wrong?

Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire