Java static methods required implementation

The task that I should have done is already set, but a certain question arises in my mind.

I defined the following interface:

package dao;

import java.sql.SQLException;

/**
 * Get / save / delete a single instance from the db in RESTful fashion on the object
 * @author kimg
 *
 * @param <T>
 */
public interface IDao<T> {

    public void fetch(int id); 
    public void save() throws SQLException; 
    public void delete() throws SQLException; 

} 

The goal is that all pojo that are represented as database entities implement these methods, so the pojo user knows how to handle instances according to the pattern. I used this approach from Backbone (Javascript).

However, there are other methods that I liked to impose as cool methods (static) on the Pojo class itself. The most obvious methods are things like:

List<Person> list = Person.fetchAll(); 
List<Person> list = Person.fetchAll(offset, limit); 
int i = Person.countAll(); 
... 

, , , . , , , ( ); , , .

?

+4
2

, , , .

, ? , ?

, , , ( )

, . , , , . , .

, , .

, . , , . , . , , , , .

, . , , , , . , , .

?

. , ( , , , ). . , , .

+2

, Entity, repo/Dao:

public interface IDao<T> {
    void fetch(int id); 
    void save() throws SQLException; 
    void delete() throws SQLException; 
    List<T> list();
    List<T> list(offset, limit); 
    int count();
} 
public class Person {
    //...getters/setters/fields...
}
public class PersonDao implements IDao<Person> {//todo make me a singleton
    //implement the interface here
}
0

Source: https://habr.com/ru/post/1627840/


All Articles