« Return to Thread: Are you really using JUnit during your development?

Re: Are interfaces unnecessarily complex? (Relates to design-for-testability)

by Jason Rogers-2 :: Rate this Message:

Reply to Author | View in Thread

J.B.¹s response is well stated.  I would like to add that simplicity is not
measured only in lines of code (that¹s like saying my productivity can
somehow be measured by KLOCs :)

I think the more telling measure of simplicity is in the maintain-ability
and test-ability of code.  This is where Interfaces show their true
strength.

-- Jason


On 9/5/06 8:54 PM, "J. B. Rainsberger" <jbrains@...> wrote:

>  
>  
>  
>
> Elliotte Harold wrote:
>
>> > Robert Martin wrote:
>>>>> >  >>> Elliotte, what are the downsides of interfaces, in your opinion?
>>>> >  >> 1. Excess complexity
>>> >  >
>>> >  > They make receiving a message more complex, it's true. They make
>>> >  > sending a message much simpler. Or rather, they add more lines of
>>> >  > code on the receiving side; but they eliminate dependencies on the
>>> >  > sending side. The benefit of those eliminated dependencies is very
>>> >  > powerful.
>> >
>> > I'm not sure I believe the second part. In practice, replacing a
>> > concrete-class based solution with an interface-based solution expands
>> > the complexity for the caller. What used to require a single class now
>> > typically requires three: a factory to create the factory, the factory
>> > itself, and the interface you're actually trying to create. I'm not sure
>> > you really need all that, but you need at least two pieces where you
>> > previously needed one, and in practice three is what we usually seem to
>> > end up with. (Think of DocumentBuilderFactory, DocumentBuilder, and
>> > Document in JAXP/DOM for example). And of course there are still
>> > concrete classes for each of these. We've turned what could have been
>> > one concrete class (Document) into six separate pieces! What could have
>> > been this:
>> >
>> > Document doc = new Document();
>> >
>> > is now this:
>> >
>> > DocumentBuilderFactory factory = DocumentBuilderFactory.getInstance();
>> > DocumentBuilder builder = factory.newDocumentBuilder();
>> > Document doc = builder.newDocument();
>
> Be careful! The Builder pattern is by no means needed to create an
> instance of an interface. JAXP/DOM combines, for whatever reason, the
> Singleton, Abstract Factory and Builder pattern, when all you really
> need is this:
>
> Document document = new WritableDocument();
>
> I could see using the Builder pattern to simplify the interface for
> constructing a document, separating creating a document from reading it,
> but by no means does JAXP/DOM do what it does because of /interfaces/.
>
> It's true that if you have a bunch of related interfaces (like in a GUI
> toolkit), you might want an Abstract Factory, but neither Singleton nor
> Builder enter the picture just because you have interfaces.
>
>> > I fail to see how that's simpler.
>
> It's not, and interfaces didn't make it more complex: the Singleton,
> Abstract Factory and Builder patterns did. If this is a representative
> example of why you find interfaces unnecessarily complex, then I really
> believe you're blaming the wrong part of the design.
>
> Take care.




[Non-text portions of this message have been removed]



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/junit/

<*> To unsubscribe from this group, send an email to:
    junit-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



 « Return to Thread: Are you really using JUnit during your development?