I know someone has probably already thought of this, but here is a way to replace DAOs and Domain objects: For example

public class Bike {

  private int id;

  public Bike(String model) {
    //Create bike object in database.
    id = getAutoIncrementKey();

  private Bike(int id) {
    this.id = id;

  public static Bike of(int id) {
    return new Bike(id);

  public String getModel()  {
    //fetch from database
    return model;

  public void setModel(String model) {
    //update in database

  public void delete() {
    //Delete in database
    id = -1;


Basically, the constructor creates the object, a static factory method is used to get an existing object, getters and setters connect to the database, and a delete method is used for deletion.

I am curious about what is wrong with this design. Can anyone tell me any problems with this and why it is not used, or tell me if this is the new Serverless?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.