Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8640233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:13:47+00:00 2026-06-12T11:13:47+00:00

Suppose I have a POJO User ,which I add some static method to do

  • 0

Suppose I have a POJO User,which I add some static method to do the CRUD operation:

public class User {
    private String name;
    private int age;

    // getter and setter omitted
    //
    public static void add(User user) {
        // add person
    }

    public static int delete(Object id) {
        // delete person
        return 1;
    }
}

Since I have other entities like User,so I want to make the add and delete method abstracted,something like this;

public class?interface Entity<T>{
    static add(T t);
    static delete(Object id);   
}

public class User extends Entity<User>{
    @override
    static add(User user){
        // add ...
    }

    ....
}

Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:13:48+00:00Added an answer on June 12, 2026 at 11:13 am

    Don’t make the CRUD methods static in the entity classes, create a generic DAO interface instead and then implement concrete DAO class for each entity type.

    Don’t use static methods for such scenario. A better and more OOP approach is to use a Dependency Injection framework that creates only one instance of each concrete DAO class to save memory and time (for creating new DAO instances again and again) and reuses those instances in all places in your application that need to access them.

    public interface Dao<T> {
    
        // you can customise these signatures by your needs
        // these are just my suggestions
    
        T get(long id);
    
        List<T> getAll();
    
        T add(T t);
    
        T update(T t);
    
        void delete(T t);
    }
    
    public class UserDao implements Dao<User> {
    
        public User get(long id) { ... }
    
        public List<User> getAll() { ... }
    
        public User add(User user) { ... }
    
        public User update(User user) { ... }
    
        public void delete(User user) { ... }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a static method of my class that returns an object of
Suppose I have a remote class that has a method with a POJO parameter:
Suppose I have a simple model, such as Record: @Model public class Record {
Suppose I have a module which defines some basic constants such as integer, parameter
Suppose I have an abstract class Person . There is another class Student which
Suppose we have the two classes given below: public class baseclass implements interface {}
Suppose you have the following object hierarchy: class Vehicle { public: virtual ~Vehicle() {}
Suppose I have a pure virtual method in the base interface that returns to
Suppose I have a class Baz that inherits from classes Foo and Bar ,
I have a simple POJO mapped to a table using Hibernate. Which works just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.