iluwatar / java-design-patterns

Design patterns implemented in Java
https://java-design-patterns.com
Other
89.75k stars 26.56k forks source link

Unit of Work pattern is Too simplified #873

Closed lihongjie0209 closed 4 months ago

lihongjie0209 commented 5 years ago

unit-of-work/src/main/java/com/iluwatar/unitofwork/StudentDatabase.java

how can u save a complex object graph with a simple modify call?

should modify update everything in object graph?

public class StudentDatabase {

  public void insert(Student student) {
    //Some insert logic to DB
  }

  public void modify(Student student) {
    //Some modify logic to DB
  }

  public void delete(Student student) {
    //Some delete logic to DB
  }
}
cloudeswift commented 4 years ago

It.s seems better to add a final prefix before String delete, modify, insert。 public interface IUnitOfWork<T> { String INSERT = "INSERT"; String DELETE = "DELETE"; String MODIFY = "MODIFY";

IAmPramod commented 4 years ago

It.s seems better to add a final prefix before String delete, modify, insert。 public interface IUnitOfWork<T> { String INSERT = "INSERT"; String DELETE = "DELETE"; String MODIFY = "MODIFY";

@cloudeswift variables of interface are final static by default. This PR is not required https://stackoverflow.com/questions/2430756/why-are-interface-variables-static-and-final-by-default