java - Where should my user interface code be located? -
where should user interface located in simple crud application (with java).
in application have main class class handles things have database e.g. getting information or adding new info it.
is wiser keep ui-elements in main class , leave database class take user input forward e.g. add new element database class, this:
public static void main(string[] args) { scanner scan = new scanner(system.in); system.out.println("give me name:"); string name = scan.nextline(); databasehandler db = new databasehandler(); db.addnametodatabase(name); } or should input prompt exist inside databasehandler, in main-class method call shown, this:
public static void main(string[] args) { databasehandler db = new databasehandler(); db.addnametodatabase(); //user interface inside addnametodatabase method }
it depends on size of program. if program small , easy read in 1 file let so. program gets bigger becomes necessary clarity break out. (if small straight procedural way of coding might best within 1 class.)
in case break out main class should driver both ui , data portions, should in different modules. might want @ different patterns mvc or mvp on how split up.
can see there no 1 way fits all. large programs broken components/modules/packages harder arms around because of wiring, make easier team work on.
Comments
Post a Comment