Java static methods required implementation -


the task had make has been delivered, yet question hangs around in mind.

i defined following interface:

package dao;  import java.sql.sqlexception;  /**  * / save / delete single instance db in restful fashion on object  * @author kimg  *  * @param <t>  */ public interface idao<t> {      public void fetch(int id);      public void save() throws sqlexception;      public void delete() throws sqlexception;   }  

purpose have pojo's represented database table entities implement these methods, user of pojo's knows how handle instances according pattern. i've taken approach backbone (javascript).

however, there other methods liked impose class methods (static) on pojo class itself. obvious methods things like:

list<person> list = person.fetchall();  list<person> list = person.fetchall(offset, limit);  int = person.countall();  ...  

i've found having these methods defined default offers great benefit, yet nothing forces developer implement them, static methods can't imposed default. also, users of classes can't know sure they'll able use static methods otherwise expect contract (in case of interface); typo in method name, omitting method can cause smooth app workflow break.

what elegant solution catch pitfall?

i've found having these methods defined default offers great benefit, yet nothing forces developer implement them, static methods can't imposed default.

if methods beneficial wouldn't developers want implement them? @ least if aware of desired patterns , usefulness of implementing them?

also, users of classes can't know sure they'll able use static methods otherwise expect contract (in case of interface)

that's irrelevant, because static methods not virtual. users do know sure whether type static method invoke in fact have method. if forget compiler gladly tell them.

any typo in method name, omitting method can cause smooth app workflow break.

i'm not sure follow you. if you're talking developers failing implement these static methods or doing wrongly, that's code review for. write automated tests reflectively verify methods' presence. don't see how bigger issue methods being implemented desired signature incorrect implementation.

again, static methods not virtual. user of every static method call knows @ compile time method being called, , therefore whether such method available. if want particular method , not have have alternatives of requesting added, adding themselves, or doing without.

what elegant solution catch pitfall?

document such expectations. have project management enforce them (and if refuse do, maybe wasn't important after all). employ code reviews. write automated tests, perhaps reflective ones.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -