Skip to content

Commit

Permalink
Drop Singleton pattern and implement Dependency Injection
Browse files Browse the repository at this point in the history
Instead of using a Singleton pattern, ensure data consistency and prevent duplication of `allAnimals` by passing the same `AnimalService` instance between controllers.
Additionally, ensure data is not loaded twice by setting a flag that must be checked before calling `loadFromDb()`.
This maintains the benefits previously established by the Singleton while reducing complexity and improving testability.
  • Loading branch information
dorian-adams committed Jan 29, 2025
1 parent 53dad71 commit d85ab1e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/crud/gsjavafx/utils/DependencyFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.crud.gsjavafx.utils;

import com.crud.gsjavafx.models.AnimalService;

public class DependencyFactory {
public static AnimalService createAnimalService() {
RescueAnimalDAO dao = new RescueAnimalDAO();
return new AnimalService(dao);
}
}

0 comments on commit d85ab1e

Please sign in to comment.