Data Model

by @im_a_muppet on October 29, 2007

So I did some research on how to implement my back end. I have decided to use the Data Access Object pattern to implement the model.

Here is my Entity-Relationship Diagram
gif_1.gif
I will implement a DAO for many of these models. And some DAO’s may access more than one ER.

For example I implemented the DAO for the EPLPlayer as follows

factory=(PlayerManagerFactoryIF)Class.forName(name).newInstance();
playerManager = factory.createPlayerManager();

The type of player manager can be read from a properties file (name is of type String). To develop the front end I created SimplePlayerManager which implements the interface PlayerManagerIF

public interface PlayerManagerIF {

  /**
   * creates an EPLPlayer based on the parameters in the 
   * playerDetails
   * 
   * @param playerDetails
   * @throws DaoException
   */
  public void createPlayer(String email, String name, String password,
                       boolean administrator) throws DaoException;

  /**
   * Updates an EPLPlayer based on the parameters set in the 
   * playerDetails
   * 
   * @param playerDetails
   * @throws DaoException
   */
  public void updatePlayer(String email, String name, String password, 
                      boolean administrator) throws DaoException;

  /**
   * delete the EPLPlayer from the manager
   * @param enailAddress
   * @throws DaoException
   */
  public void deletePlayer(String emailAddress) throws DaoException;

  /**
   * Get the EPLPlayer based on the email address
   * @return an EPLPlayer
   */
  public EPLPlayer getPlayer(String emailAddress);

  /**
   * get all the players 
   * @return a Collection of EPLPlayers
   */
  public Collection<EPLPlayer> getAll();    
}

This SimplePlayerManager just hard codes some basic setup so that I can concentrate on developing the Controller and View. I will eventually implement a JDBCPlayerManager that will access a MySql database.

This pattern decouples the model from the view and even the controlled. In the controller I can specify which DAO type I want to use. Everything else stays the same. As well as helping me implement a SimplePlayerManager for prototyping it also provides maintainability to the application. If we needed to change the model to a file or a different database then that would be possible without having to change a lot of code. All we would need to do is implement a new DAO (e.g. XMLFilePlayerManager) and then change the properties file. There will be no code change for the rest of the project.

blog comments powered by Disqus
Tweet