It's true that many uses of interfaces are simply adding a skin to a concrete class. There's no real sense of an object playing one or more roles. 'Customer' is a nice example, because it sounds too general to describe a role. A Customer class that implements, say, Purchaser, might be more appropriate.
It's about expressing relationships in the code, and trying to make dependencies as narrow as possible.
S.
Steve Freeman
Winner of the Agile Alliance Gordon Pask award 2006
Book: http://www.growing-object-oriented-software.com
+44 (0) 797 179 4105
M3P Limited. http://www.m3p.co.uk
Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
Company registered in England & Wales. Number 03689627
Thanks,
James
S.
They are Novice principles. I appreciate Jason's perspective, and I
think I understand it, but when I teach novices, I need to give them
rules to follow. I give them these rules to help lead them towards
learning the "more fundamental and nuanced principles". I hope Jason
remembers what it felt like to learn modular design principles for the
first time.
> If the only class that ever implements the
> Customer interface is CustomerImpl, you don't really have polymorphism
> and substitutability because there is nothing in practice to
> substitute at runtime. It's fake generality. All you have is
> indirection and code clutter, which just makes the code harder to
> understand.
Jason appears not to have mastered the difference between "I don't
like it" and "It's bad".
--
J. B. (Joe) Rainsberger :: http://www.jbrains.ca ::
http://blog.thecodewhisperer.com
Diaspar Software Services :: http://www.diasparsoftware.com
Author, JUnit Recipes
2005 Gordon Pask Award for contribution to Agile practice :: Agile
2010: Learn. Practice. Explore.
> "What I can say with confidence is that religiously following…"
…and I'm out of the discussion.
--Nat
On 5 September 2010 21:12, philip schwarz
Regards,
Lance
> A very brief addition to this thread: a Mock Object *is* another
> implementation of the interface. Ok, it's for testing not production
> code. But that doesn't make the need of its existence any less valid.
> Tests are as much part of the system as the code that runs in the
> deployed system (and in many systems, some of the tests *are* included
> in with and run in the deployed system).
Yup. I just don't have much faith in Gorman finding that argument the
slightest bit interesting, even though it seems pretty obvious to you
and to me and to many here.
> I actually don't buy the 'if it's only got one implementation, the interface is redundant' argument any more than the 'if a method is only called from one place it should be inlined' argument. Both give a name to an abstraction and that has enough value for me.
I find two broad reasons to use interfaces: as a seam to introduce
sensible polymorphism and as a seam to enable relayering. Gorman
appears to value only the former. I value that latter, and don't mind
treating it as scaffolding that might never quite disappear. I equate
designing a system more to painting a long suspension bridge (you're
never done, so the scaffolding moves around, but never disappears)
rather than erecting a single building.
I'm thinking about stuff like
Client implements IClient
DaoImpl implements Dao
etc.
cheers
Uberto
Most of the time I can easily figure out what's special about the
production implementation of an interface. When I can't, then I
suspect a layering problem. It usually is.
On Mon, Sep 13, 2010 at 15:11, J. B. Rainsberger <m...@jbrains.ca> wrote:
> On Mon, Sep 13, 2010 at 06:34, Uberto Barbini <ube...@ubiland.net> wrote:
>> I agree with:
>> 'if it's only got one implementation, and the interface has (more or
>> less) the same name of implementation, them there is a strong smell
>> for the interface to be redundant'
>>
>> I'm thinking about stuff like
>> Client implements IClient
>> DaoImpl implements Dao
>
> Most of the time I can easily figure out what's special about the
> production implementation of an interface. When I can't, then I
> suspect a layering problem. It usually is.
I don't understand your reply. I assume 'layering problem' means
there's some code in one layer that should be in another layer, but I
don't see how that relates to interface/implementation?
Could you give me more context and/or an example?
Many thanks,
- Kim