java - Is placing all setters of derived class to util class a good design? -


i read codes this:

public class base {     protected map<string, object> attrmap = new hashmap<>();     public map<string, object> getattrmap() {         return this.attrmap;     } }  public class deriveda extends base{}  public class derivedb extends base{}  public class util {     public void setderivedaattrx(base base, object object) {         base.getattrmap().put("deriveda_x", object);     }     public void setderivedaattry(base base, object object) {         base.getattrmap().put("deriveda_y", object);     }     public void setderivedbattrx(base base, object object) {         base.getattrmap().put("derivedb_x", object);     }     public void setderivedattrz(base base, object object) {         base.getattrmap().put("derived_z", object);     } } 

i asked implementor of codes why design this, here answer:

  1. we can't let setters in base, because it's set derived attributes.
  2. if move setters corresponding derived class, it's hard handle setderivedattrz.(note can set attribute z both deriveda , derivedb)we may have base reference , set attribute z. know it's deriveda or derivedb indeed, don't know it's 1 exactly. can't cast derived class , call derived setters.
  3. since place these setters in base or derived class both have shortcomings, comes util class handle setters.

so question, design case?

i think bad design. basic of object-oriented programming call methods on objects, , not helper functions objects , method parameters passed.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -