简体   繁体   中英

Reduce Service layer and DAO in Spring Java

I came across a SO question which says that Service and DAO could have the same content, and after exploring my functions in both Service and DAO, the functions are exactly the same. I know that the DAO is for DB queries, and the Service is for logic question, but how can I reduce the functions of each of those as I have this in Service :

public interface PlatformService {
    public void addPlatform(Platform platform);
    public void updatePlatform(Platform platform);
    public Platform getPlatformById(int id);
    public List<Platform> getPlatform();

}

and in DAO :

    public void addPlatform(Platform platform);
    public void updatePlatform(Platform platform);
    public List<Platform> getPlatform();
    public Platform getPlatformById(int id);

}

that are exactly the same! I don't know, if removing anything from a part will change the app speed or the app won't be functional at all?

If you remove any part from, it won't function properly, but it won't improve the speed. The service layer is optional , you can write your app without it.

If you want, you can directly create ServiceImpl without Service interface, but it's not increase the speed significantly. Then you get disadvantage when the data access is changed.

The main reason you create Service layer is to maintain the ServiceImpl when the data access is changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM