Java: everything in a class is static - is this reasonable? -


i 'm wondering if i'm doing somehow poor design.

i have arraylist of things. need list exist. need have 1 of these lists. have methods interact list. thusly, made static.

the thing since of these things tucked away single class, literally in class declared static. seems bit odd, because it's want have entire class static.

the facts java doesn't allow me make entire class static , taught minimize static methods in code setting off few alarm bells in head, can't see rational reason why i'm doing won't work well.

edit: bit more program , why decided did, because guess (and asked, of course).

the center of program 2 databases, 1 items , characters. characters need have temporary posession of items, items must able listed @ times.

i decided have arraylist of items, each item having boolean marking available or not available (making easy display both items , available items). each character have own, smaller arraylist of items, add duplicates of item database.

to able access database other classes (this started idea), considered easiest option make large arraylist static because there no situation need not exist , there no situation need more one. of course, made list static, needed make of basic methods of interacting static well.

i'm pretty sure there better ways of doing i'm trying do, i'm beginner practising.

edit2: oh, , list of items added to, removed from, , it's items modified while program runs. effect of characters receiving copies of items own items remain same long have them.

based on update, you've arrived @ classic "it's singleton!" moment, after should point out "it's (almost) never singleton!". instead, should normal, non-static, non-singleton class, , rest of application should written use single instance of it. fact application needs single instance of thing doesn't make thing singleton. you'd benefit reading several of articles turn google searches "why singleton evil" , "singleton antipattern".

it's sounding might talking shared mutable state, whole other (giant) can of worms don't want without careful consideration.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -