Interfaces, what if not all implementations use all methods?

implementation, interface, java

Solution

IMO, for the middle stage - it is OK to use `NotImplementedException`, until you finish implementing it.

However, as a permanentsolution - I believe it is a bad practice [in most cases].

Instead, I'd create an interface that contains behavior common to all implementing classes, and use subinterfaces to cluster them up for more specific behavior.

The idea is similar to java standard `SortedSet`, which extends a `Set` - we wouldn't want to regard `Set` as `SortedSet`s and give a variable of this type a value of `HashSet`, instead we use a sub-interface, `SortedSet` for this purpose.

Problem

I'm fairly new to programming against interfaces and am trying to get it right as a major tool for developing test driven. Currently we have a lot of Manager classes that all implement a `CRUD` interface. However some Managers don't yet do updates and some don't do delete, some may never do so. Not implemented exception? Is it okay, to just ``` throw new NotImplementedException() ``` until the method gets implemented or even for all time if it never does? (obviously with a source code comment telling the programmer "this method is not supposed to be used, as e.g. Types like 'male' 'female' do never get deleted)? Split? Or should I split my CRUD interface into Creatable, Readable(Searchable), Updatable and Deletable? Wouldn't that clutter my class definition? ``` PersonManager implements Creatable<Person>, Updateable<Person>, Deletable<Person>, Searchable<Person> ``` Split and combine? Or should I combine some interfaces like all 4 into CRUD and maybe some other combinations like Read + Update? Maybe that would also create a load of interfaces where one has to click through a big inheritence path to find out which interface implements all the desired atomic interfaces for the current situation (I need read and create, so which one just implements the two? and this can get a lot more complex quickly)

Original source