Skip to content

Commit

Permalink
removed aggregation relationship of CarDatabase and RentalDatabase
Browse files Browse the repository at this point in the history
  • Loading branch information
yuans-dev committed Jul 25, 2024
1 parent c2ad8c3 commit 8177567
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/crms/form/MainForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ public void warn() {

private void initializeProgram() {
carManager = new CarManager(CarDatabase.getInstance());
rentalManager = new RentalManager(RentalDatabase.getInstance(CarDatabase.getInstance()));
rentalManager = new RentalManager(RentalDatabase.getInstance());
updateCarTable(carManager.generateReport());
}

Expand Down
16 changes: 6 additions & 10 deletions src/crms/lib/RentalDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;

/**
* The {@code RentalService} class is responsible for managing rental operations
Expand All @@ -26,28 +25,24 @@ public class RentalDatabase extends Database<Rental> {

private final String filename = "rentals.txt";
private static RentalDatabase instance;
private CarDatabase carDatabase;

/**
* Private constructor to prevent instantiation. Initializes the rentals
* list.
*/
private RentalDatabase() {
dataList = new ArrayList<>();
}

/**
*
* private RentalDatabase() { dataList = new ArrayList<>(); }
*
* /**
* Returns the singleton instance of {@code RentalService}. If the instance
* does not exist, it is created and the rentals are fetched from disk.
*
* @param carManager the {@code CarInventory} instance required to fetch
* associated {@code Car} objects.
* @return the singleton instance of {@code RentalService}.
*/
public static RentalDatabase getInstance(CarDatabase carDatabase) {
public static RentalDatabase getInstance() {
if (instance == null) {
instance = new RentalDatabase();
instance.carDatabase = carDatabase;
instance.fetchFromDisk();
}
return instance;
Expand Down Expand Up @@ -81,6 +76,7 @@ public void fetchFromDisk() {
while (reader.ready()) {
String text = reader.readLine();
String[] lineComponents = text.split("###");
var carDatabase = CarDatabase.getInstance();
try {
Car car = carDatabase.getItemById(lineComponents[2]);
if (car == null) {
Expand Down

0 comments on commit 8177567

Please sign in to comment.