Most of my classes must implement two of the three above, such that my class definitions (before implementing the necessary methods) would look like this:
That works fine, but I am wondering if pairing the interfaces into subinterfaces is a defensible methodology. For example, all classes that act like Producer must implement both the Source and Sender interfaces. And all classes that act like Relayer must implement the Sender and BlackHole interfaces. I could define two subinterfaces like this:
I could then define my classes like this:
Within the class definitions, it makes no difference, as I will have to implement the same methods either way. But it seems more self-documentary to create the subinterfaces from their parent interfaces and name them in ways that reflect what the classes that implement them must actually do.
Is this a good idea, obfuscatory, or something else?
If so, write a Factory interface.
Is there such an entity as a factory in my “world”?
By the way: miss out the methods' access modifiers in the interfaces; the methods are public by default in a public interface.
Stevens Miller wrote:That works fine, but I am wondering if pairing the interfaces into subinterfaces is a defensible methodology.
Seems fine to me. What I'm not so sure about is whether Producer, Relayer and Consumer are actually classes; they look much more like interfaces to me as well.
I think, if I was doing this, I'd then be tempted to create skeleton implementations of each of them with abstract classes (AbstractProducer, AbstractRelayer and AbstractConsumer?) that cover the majority of cases you're likely to need. That would then save you the trouble of coming up with "interface names" for interfaces that basically define the same types as your classes currently do.
However, it's only one possibility; there are plenty of others.
Stevens Miller wrote:Thanks, folks! Just what I needed in the way of feedback.
I work alone, so there's no one in the next cube to talk to about things like this (because, well, there's no "next cube" here).
Glad we could help. Welcome to JavaRanch, and feel free to think of us as your "next cube".
Stevens Miller wrote:Good gracious, Winston. I know I've been away for a while, but don't you remember me?
Ooof. My apologies. For some reason I read '2' under your 'Number of posts' (I think I must have read your 'Number of cows'), and didn't even note the name.
Put it down to Alzheimer's...or too much beer. That's my excuse.