Java overriding static method -


i have found myself in need override static method, because makes sense, know not possible.

the superclass, entity.java:

abstract public class entity<t> {     public entity() {         //set database connection     }      abstract public static map<object, t> getall();      abstract public void insert();      abstract public void update();      protected void getdata(final string query) {         //get data via database     }      protected void executequery(final string query) {         //execute sql query on database     } } 

one of many concrete implementations, account.java:

public class account extends entity<account> {     private final static string all_query = "select * accounts";     private final static string insert_query = "insert accounts (username, password) values(?, ?)";     private final static string update_query = "update accounts set password=? username=?";      private string username;     private string password;      public account(final string username, final string password) {         this.username = username;         this.password =  password;     }      public string getusername() {         return username;     }      public void setusername(final string username) {         this.username = username;     }      public string getpassword() {         return password;     }      public void setpassword(final string password) {         this.password = password;     }      @override     public static map<object, account> getall() {         //return map using all_query string, calls getdata(string);     }      @override     public void insert() {         //insert using insert_query, calls executequery(string);     }      @override     public void update() {         //update using update_query, calls executequery(string);     } } 

i haven't been going in depth explaining code, general feedback on appreciated, hope comments explain enough.

so think can agree using account.getall() makes more sense on new account().getall() (if introduce dummy syntax it). want have extend entity class, convienience, later on may have use sets/lists/multisets of entity , perform update() action on of them, example if build queue performances updates every minute.

so well, there way construct getall() correctly?

regards.

you have separate classes operations on elements:

abstract public class collection<t extends entity<t>> {     abstract public static list<t> getall();     public void printall() {         // print entries of list obtained getall()     } } 

which use as:

public class accounts extends collection<account> {     @override     public list<account> getall() {         //return list using all_query string, calls getdata(string);     } } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -