New answers tagged

1

One function, multiple signatures There is no other pattern, you either pass a connection or you don't. However JS is a very expressive language so there are many ways to achieve the same result. Using default parameters and the best option. function addUser(con = knex) { return con.insert({username: 'newuser'}).into('users'); } Using ?? (Nullish ...


1

Prefer interfaces to implementations private HashMap<String, ToDoList> toDoLists; private HashMap<String, User> map; You should almost never use an implementation as the type. So these should be private Map<String, ToDoList> toDoLists; private Map<String, User> map; Then if you change the implementation, you only ...


2

You improved the program by a lot but then misunderstood some of @TorbenPutkonen's suggestions. As it turns out, the program runs just as fine when you change all StorageInstances to Storage and remove the interfaces you added. The Storage instance Let's get the StorageInstance out of the way first. Consider a line like this Storage store = new Storage(); ...


Top 50 recent answers are included