transMorphic
Mike Roberts' blog on tech and life














Subscribe to "transMorphic" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.
 

 

03 December 2002
 

Interfaces considered Important.

Coding Conventions - _I_ want to kill the Impl.

<Snip>

 What I do know, however, is that classes are the principle objects in Java, not interfaces. Interfaces are handy, dandy and cool, but they're there to help structure your classes and allow interoperation without multiple inheritance, NOT to be the prime way of programming. If you're thinking "I'll just program to interfaces and forget about those classes", you need to come up to speed because I think that fad went out a couple years ago.

-Russ [Russell Beattie Notebook]

This is interesting, mostly because I used to agree, and now disagree (sorry Russ). I think interfaces are one of the most under-used and useful parts of Java. I certainly believe that if you do have a class and an interface that it implements, the interface gets priority, ie. the unadorned name of the thing. <snip>

 [Pushing the envelope]

Simple example:

	List myList = new ArrayList();

Do I care what class 'myList' is? No, not at all. So here, programming to interfaces is totally legitimate. If in a round of performance optimisation someone wants to go and change the class used they can (as long as the test suite still works, of course ;) )

However, I'm by no means an 'everything must be interface / implementation separated' kind of guy. I personally think that interfaces should appear out of refactoring (normally - if you're making a public API then that might be a different matter, but I'm not going to try and think about 'test-first APIs' here!)

Regarding naming though, I hate calling things 'Ifoo', and I'm kind of inbetween about whether 'FooImpl' is a great thing. If you are only producing Interfaces out of refactoring there's probably going to be more that one implementation anyway, so calling it just plain 'FooImpl' isn't a great idea since that implies that there's only one significant implementation.


2:35:02 PM    


Click here to visit the Radio UserLand website. © Copyright 2003 Mike Roberts.
email : blog @ tmorph . com

Last update: 11/02/2003; 00:06:29.
This theme is based on the SoundWaves (blue) Manila theme.
December 2002
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Nov   Jan