At the end of the day, some would say there's really no functional
difference between the two.

But as for a preference for interfaces, well, partly it's due to the
limitation of single inheritance in Java.  Using interfaces provides the
functionality of acting as a derivative of multiple base classes, without
bumping into any of the difficulties or heartache in a language that does
allow true multiple base classes.

Another reason is that using interfaces allows a simpler extension point
that others can use in the future, without necessarily inheriting any of
the other miscellaneous members in a base class that would not actually be
used (which may not have been originally properly scoped in the base).

Defining an interface during a design phase also forces you to think long
and hard about what is the true *core* functionality of the object you're
trying to model, i.e., what are the minimal characteristics that such an
object satisfying this role would require, whether that role is what a
method returns or what it takes as a parameter.

So this process of stripping down some problem domain to its core "verbs",
so to speak, does help streamline the design process somewhat, i.e.,
forcing you to think purely in terms of functionality as these are exposed
through methods, rather than also having to think about how data members
may or may not fit in, or the interaction between these "verbs" and the
data it acts upon, which is something that would come up when you're
thinking of designing something through inheritance of base classes.

HTH, my 2 cents.




                                                                           
             Carl Smith                                                    
             <ccsmith20002001@                                             
             yahoo.com>                                                 To 
                                       Struts Users Mailing List           
             08/10/2005 10:47          <user@struts.apache.org>            
             AM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         Why interface                       
               "Struts Users                                               
               Mailing List"                                               
             <[EMAIL PROTECTED]                                             
                  he.org>                                                  
                                                                           
                                                                           





In Java/J2EE community, it seems that a lot of experienced developers tend
to use a lot of interfaces, however, a lot of junior developers ignore
using interface. I am not sure why interfaces seem to be favorite to some
experienced developers. Can some one explain this?Can you give examples
where an interface is preferred?

Thanks.





__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to