oop - java - design patterns - inheritance with static variables -


i have person class extends record class , i'd define database table name, columns, , column types static variables in person class. i'd following can't because can't modify objects when not in method(i think? java noob here).

class person extends record{     protected static final string dbtable = "people";     protected static linkedhashmap<string, string> dbcolumns = new linkedhashmap<string, string>();     dbcolumns.put("id","integer");     dbcolumns.put("name", "text"); } 

i following looks messy , not readable if table has several columns

class person extends record{     protected static final string dbtable = "people";     protected static final string[] dbcolumns= {"id","name"};     protected static final string[] dbcolumntypes= {"integer","text"};  } 

i don't want define these in constructor because want static method in parent class(record) can following list of person records

list<person> people = person.getall(); 

my initial thought create following abstract methods in record class , implementation in person class return appropriate static variables.

public abstract string gettablename(); public abstract string[] getcolumnnames(); public abstract string[] getcolumntypes(); 

but can't because static method, getall(), can't reference non-static methods. how let static method, getall(), aware static variables exist in extended class , can use them?

i'm know there's correct way go doing this, can't figure out.

you you're doing abstract methods, , need change static getall() getall(record record) , have call methods.

you're on right track. avoid relying on static things outside of class in favor of exposing instance methods may call private or protected static fields, personally.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -