Joey Hipolito
Joey Hipolito

Reputation: 3166

Reading textfile in java using data access object

Last day my professor fed us some lectures that he wasn't able to teach very well. Although I have a good background in php, but it's kinda different in java, especially the design patterns. He was blabbering about mvc, which is I think different with php's mvc design pattern.

Here is the problem, he posted some codes over the screen which includes 3 files

  1. data-access-object with a method which does the following (based on my understanding):

    • return an object that has 3 values accountNumber, pinCode, balance
  2. model? that has setters and getters on it that gets or sets accountNumber, pinCode and balance

  3. and lastly the test which contains the main class, a place where we are to run the code.

I just want to understand or see a better example of this Automated Teller Machine stuffs that uses DAO for accessing a textFile

or maybe can someone just post his/her flowchart, coz i really do not understand it on my own.

Upvotes: 0

Views: 1929

Answers (1)

Random42
Random42

Reputation: 9159

He was blabbering about mvc, which is I think different with php's mvc design pattern.

Design patterns are independent of the language you use.

data-access-object with a method which does the following (based on my understanding):

  1. return an object that has 3 values accountNumber, pinCode, balance

  2. model? that has setters and getters on it that gets or sets accountNumber, pinCode and balance

  3. and lastly the test which contains the main class, a place where we are to run the code.

You should start with your model fist; you just need a bean

   public class Account {
        private String accountNumber;
        private int pinCode;
        private long balance;   

        //constructors, setters and getters
    }

Then you need to create the DAO class which should look something like this:

public interface AccountDAO {
    public Account getAccount(String accountNumber);
    //and other methods
    public List<Account> getAllAccounts(); //this is not suitable for a real bank app
    public void writeAccount(Account account);
    public void deleteAccount(Account account);
    public void updateAccount(Account oldAccount, Account newAccount);
}

Having this interface you can implement specific AccountDAO, like FileAccountDAO, XmlAccountDAO, DatabaseAccountDAO.

Upvotes: 2

Related Questions