05 Data Access
05 Data Access
PERSIST?
CSC 207 SOFTWARE DESIGN
1
LEARNING OUTCOMES
• Understand how to read and write text files, along with all the Java
warts.
2
THE PARTS OF AN ENGINE TO MAKE A FEATURE WORK
Interface Adapters < DS > Enterprise Business Rules
Input Data
<I>
Controller Input Boundary Use Case
Entities
Interactor
<I>
Presenter Output Boundary
< DS >
Output Data <I>
< DS > Data Access
View Model Interface
Application Business Rules
3
PROGRAM DATA: PERSISTENT DATA
Interface Adapters < DS > Enterprise Business Rules
Input Data
<I>
Controller Input Boundary Use Case
Entities
Interactor
<I>
Presenter Output Boundary
< DS >
Output Data <I>
< DS > Data Access
View Model Interface
Responsibility: manage access to
Application Business Rules
persistent data (reading from and
writing to files or databases), creating
View
temporary Entities that the Use Case Data Access Database
5
FILE FORMATS
These are all structured plain-text file formats:
• csv file
• json file (more expressive than csv)
• These look like Python dictionaries.
• xml file (bulkier expressive format)
See https://www.json.org/example.html for both json and xml examples.
6
HOW DATA PERSISTS IS A DETAIL
• The specifics of how we save and load data for our program should be in the
outer layer of our design.
• We can design an interface for what it means to save/load, then we are free to
implement it using any of the approaches mentioned!
• For today, let's take a look at how saving some entities from last week might look
if we were to use a local csv file to store our entities.
• https://github.com/paulgries/UniversityExample
7
RESOURCES
A tutorial about reading / writing files in Java:
• https://docs.oracle.com/javase/tutorial/essential/io/file.html
We worked with csv files today, but we did all the processing manually
(which can be error prone and hard to maintain). Using a library like
openCSV is an alternative you might find interesting to explore:
• https://www.geeksforgeeks.org/reading-csv-file-java-using-opencsv/
10
HOMEWORK
11