Java và MySQL – DatabaseDAO Singleton

DatabaseDao Interface

package binh.dev.data.dao;

public abstract class DatabaseDao {

    private static DatabaseDao instance;

    public static void init(DatabaseDao inst) {
        instance = inst;
    }

    public static DatabaseDao getInstance() {
        return instance;
    }

    public abstract ProductDao getProductDao();

    public abstract CategoryDao getCategoryDao();

    public abstract OrderItemDao getOrderItemDao();

    public abstract OrderDao getOrderDao();

    public abstract UserDAO getUserDao();

}

Database Implement

package binh.dev.data.dao;

import binh.dev.data.impl.CategoryImpl;
import binh.dev.data.impl.OrderImpl;
import binh.dev.data.impl.OrderItemImpl;
import binh.dev.data.impl.ProductImpl;
import binh.dev.data.impl.UserImpl;

public class Database extends DatabaseDao {

    @Override
    public ProductDao getProductDao() {
        // TODO Auto-generated method stub
        return new ProductImpl();
    }

    @Override
    public CategoryDao getCategoryDao() {
        // TODO Auto-generated method stub
        return new CategoryImpl();
    }

    @Override
    public OrderItemDao getOrderItemDao() {
        // TODO Auto-generated method stub
        return new OrderItemImpl();
    }

    @Override
    public OrderDao getOrderDao() {
        // TODO Auto-generated method stub
        return new OrderImpl();
    }

    @Override
    public UserDAO getUserDao() {
        // TODO Auto-generated method stub
        return new UserImpl();
    }

}