• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The uses of Interfaces

 
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think interfaces are the most powerful construct of an OO language.
Of a language like Java, anyway.
I am trying to compile a list of the uses.
1: The fields and methods that a class permits objects of other classes to access
Your design may perhaps require a more complex definition of an interface as in :
2: ADAPTOR - here you use the interface to adapt a class's interface to meeet different client's needs
3: FACADE - here you use it as an interface to a collection of classes.

This is one of the limitations of the GoF book that C++ && Smalltalk do not have the interface construct.
Are there other definitions of use of interfaces that are realized in Patterns ? Or may be not yet realised in a Pattern?
regards
[ August 19, 2003: Message edited by: HS Thomas ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by HS Thomas:
I think interfaces are the most powerful construct of an OO language.
Of a language like Java, anyway.


Yeah - in dynamically typed languages, on the other hand, they are totally useless...

This is one of the limitations of the GoF book that C++ && Smalltalk do not have the interface construct.


A purely abstract C++ class is equivalent to a Java interface. And in Smalltalk, interfaces would be pointless, as it doesn't need inheritance to do polymorphism.
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


A purely abstract C++ class is equivalent to a Java interface. And in Smalltalk, interfaces would be pointless, as it doesn't need inheritance to do polymorphism


Oh , I see you are saying there weren't any limitations in GoF in that case.
Sorry , dynamically typed languages have eluded me so far. Have I missed anything by way of experience ? Python sounds useful.
--------------------------------------------------------------------------
Well-known dynamically typed languages, in each of the major language paradigms, include the following:
Lisp and its dialects (which are functional programming languages)
Perl (a mostly procedural programming language, though opinions vary as to this point)
Smalltalk (an object-oriented programming language).
Other dynamically typed languages include:
Ruby (a clean, pure-OO, interpreted language that gets out of the way and makes it easy to code in whatever style you deem appropriate.)
Python (a multi-paradigm language supporting all three styles)
--------------------------------------------------------------------------
regards
[ August 19, 2003: Message edited by: HS Thomas ]
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, how should you think of interfaces, then ?
As a type of abstract class with only abstract methods ?
An abstract class is MUCH more powerful than that ! Ooops.
So an abstract class is the most powerful construct in an object language.
regards
[ August 19, 2003: Message edited by: HS Thomas ]
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, then, interfaces are the *most used* design construct.
You can't seem to do much without having to design an interface !
And they do afford you the most flexibility. i.e. They give flexibility at a cheap price.( What could go wrong with an interface that couldn't be put right quickly ? Other than smelly duplicate code ? )
( BTW Apparently Smalltalk programmers agree that inclusion of interfaces was a good thing, but I've also heard that Smalltalk Designers [brought up on The Design Patterns Smalltalk Companion and Smalltalk Best Practice Patterns ] make better OO designers :roll: )
regards
[ August 19, 2003: Message edited by: HS Thomas ]
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And another thing, if one writes tests through interfaces (and presumably mock objects) then one designs around interfaces and the other design constructs are refactored in to reduce smells.
regards
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by HS Thomas:
Sorry , dynamically typed languages have eluded me so far. Have I missed anything by way of experience ? Python sounds useful.


Programming in a dynamically typed language is quite different from programming in Java or the like. I would rather go with Ruby or Smalltalk.
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Illja.
regards
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic