Can I reduce this reoccurring pattern in my Java class? -


i have following interface:

public interface gravy {       public list<giblet> getgiblets();      public giblet getgiblet(string id);      public int getnumgiblets();      public void addgiblet();      public void removegiblet(giblet giblet);       public list<carrot> getcarrots();      public carrot getcarrot(string id);      public int getnumcarrots();      public void addcarrot();      public void removecarrot(carrot carrot);       public list<gravy> getgravies();      public gravy getgravy(string id);      public int getnumgravies();      public void addgravy();      public void removegravy(gravy gravy);  } 

as can see, have reoccurring pattern in gravy. gravy object can contain giblets, carrots, , other (smaller) gravies. of can added to, removed from, or queried.

two things note:

  1. carrots , giblets have bit in common each other, both differ vastly gravys.

  2. i may need add more items later on (thus need refactoring)...

is possible reduce above code "verbs" written once?

it depends on how similar consider group of functionality. example, if group of functionality can considered in itself, e.g. set of ingredients, following:

public interface ingredient<t> {      public list<t> getall();      public t get(string id);      public int size();      public void add(t item);      public void remove(t item); }  public interface gravy {      public ingredient<giblet> getgiblets();      public ingredient<carrot> getcarrots();      public ingredient<gravy> getgravies(); } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -