0% found this document useful (0 votes)
20 views

05 Data Access

This document discusses how data persists in applications. It explains that most persistent data is saved in databases, and for the course plain text files are a good option. It provides examples of different file formats like CSV and JSON that can be used. The document emphasizes that the specifics of how data is saved and loaded should be abstracted away in the outer layers of the application design. It provides an example of how entity data from last week's lesson could be saved to and loaded from a local CSV file. It also includes additional resources on reading and writing files in Java.

Uploaded by

gharbismael
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

05 Data Access

This document discusses how data persists in applications. It explains that most persistent data is saved in databases, and for the course plain text files are a good option. It provides examples of different file formats like CSV and JSON that can be used. The document emphasizes that the specifics of how data is saved and loaded should be abstracted away in the outer layers of the application design. It provides an example of how entity data from last week's lesson could be saved to and loaded from a local CSV file. It also includes additional resources on reading and writing files in Java.

Uploaded by

gharbismael
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

HOW DOES DATA

PERSIST?
CSC 207 SOFTWARE DESIGN

1
LEARNING OUTCOMES
• Understand how to read and write text files, along with all the Java
warts.

• Better understand the Data Access corner of the Clean Architecture


diagram.

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

View Data Access Database

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

uses to do its work.


4
HOW IS DATA PERSISTENT?
Most persistent data is saved in databases. (CSC343)
For this course, plain text files are a fine choice, although you can use a
database if you’re feeling ambitious.
For the Uni example, we’ll look at code that reads and writes Person and
Student data to a CSV file.
Serialization is another option that’s pretty cool. It’s not required material for
CSC207 this year.
• https://stackoverflow.com/questions/633402/what-is-serialization
• https://chat.openai.com/share/47c8e84c-dd39-4749-8570-ffa66f06784a

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.

Databases are not plain text.


Serialization files are not plain text.

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

• Complete your weekly


activities and continue
learning Java.

• If you aren’t on the course


piazza yet, please sign up.

11

You might also like