as a follow up on my previous question Having a function with combined generic bounds such as:
<T extends Foo & Bar> void doStuff(T argument) {
//do stuff wich should only be done if arguments is both foo and bar
}
Because this is not castable from a unspecified object, you need to have knowledge of some object which actually implements these interfaces. it seems to me that needing to know the specific type of the object argument to pass to doStuff(T a)
is a violation of Demeter's law.
The function doesn't specify the need to know the actual class (there could be many different ones), and i really don't want to know it as knowing this class increases the dependency in my code base.
is using these bounds an anti pattern? and if so how should one best avoid it?
the case scenario involved one interface specifying the object is persistent and the other specified object having a related entity. the doStuff(T a)
function in this case persisted the related entity when it was persisted. however nonpersistent entities can also have a related entity, but should not be processed by the doStuff(T a)
function