vendredi 23 décembre 2016

What is the correct way to implement a Creator Class and the Class itself design in Java?

so I am facing a question here. I am trying to decide on a design for all my Classes and they're Creators.

For example I have 2 classes, Level and LevelLoader: The design I have come so far is: This is Level class:

public class Level implements Serializable{

    private byte[] map; 

    Level(LevelLoader loader){
        map=loader.getMap();
    }

This is the Creator:

public interface LevelLoader {

    public Level loadLevel(InputStream stream);

    public byte[] getMap();

}

So for example to create a level instance in main file i'll write: TextLoader is implementing LevelLoader interface above:

File file=new File("src/Level/level2.txt");

Level level1=new Level(new TextLoader(file));

So I am curious what is the most logic way to connect between the two ?

Tahnk you.

Aucun commentaire:

Enregistrer un commentaire