vendredi 17 novembre 2017

Java - Factory, Instance

public class DataFactory {

    class SYNOP implements IDataSources {}
    class WRF implements IDataSources {}

    public abstract class Factory {
        public abstract IDataSources CreateModel();
    }

    public class SYNOPFactory extends Factory {

        @Override
        public IDataSources CreateModel() {
            return new SYNOP();
        }
    }

    public class WRFFactory extends Factory {

        @Override
        public IDataSources CreateModel() {     
            return new WRF();
        }       
    }

    public static void main(String[] args) {

        Factory factory = new WRFFactory();

    }
}

And i got message error like this:

No enclosing instance of type DataFactory is accessible. Must qualify the allocation with an enclosing instance of type DataFactory (e.g. x.new A() where x is an instance of DataFactory).

What did i do wrong?

Regards

Aucun commentaire:

Enregistrer un commentaire