Matej Kralik Matej Kralik - 26 days ago 12
Java Question

How design pattern is this?

I need help. I am searching on the internet how to call design pattern for my code but I haven't found it.
I have a class (f.e. exercise) with getter and setter and manager which have all exercise (in the DB or array, doesn't matter). In my application, I have the one instance of exercise manager and I work with exercises through it.

Exercise :

public class Exercise {
private Long id;
private String name;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}


Exercise manager:

public interface ExerciseManager{
void createExercise(Exercise exercise);

Exercise getExerciseById(Long id);

Collection<Exercise> getAllExercises();

Exercise getExerciseByName(String name);

void updateExercise(Exercise exercise);

void deleteExercise(Long id);

Boolean isIdInDB(Long id);
}

public class ExerciseManagerImpl implements ExerciseManager{
...
}


Main (f.e.):

public static void main(String[] args) {
DataSource dataSource = <some datasource>;
ExerciseManager exerciseManager = new ExerciseManagerImpl(dataSource);
Exercise newExercise = new Exercise();
newExercise.setName("Name1");
exerciseManager.createExercise(newExercise);
Exercise existExercise = exerciseManager.getExerciseByName("Name1");
exerciseManager.deleteExercise(existExercise.getId());
}

Answer

This looks like a data access object, which would be part of your persistence layer; it serves as an interface between application code (which uses Exercise instances) and a persistence mechanism (such as an EXERCISES database table), decoupling the former from the latter.