Matej Kralik Matej Kralik - 1 year ago 80
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) { = name;
public Long getId() {
return id;
public void setId(Long 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();
Exercise existExercise = exerciseManager.getExerciseByName("Name1");

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download