Program to an interface, not an implementation

Sean 'Shaleh' Perry shalehperry at attbi.com
Thu Jun 6 12:01:33 EDT 2002


On 06-Jun-2002 Egbert Bouwman wrote:
> Hello,
> Can someone shed some light on the GoF adagium:
> 'program to an interface, not an implementation'
> and especially what it means for programming in Python ?
> GoF is not easy.

Sure we can even use python as the example (-:

Any object can act like a list or a dict if they implement the right methods. 
This is an interface.

l = [1,2,3] # use a python list

uses the implementation.

To further this, if your class included code which made decisions based on how
you knew say dict was implemented rather than just using ['string'] or
.has_key() that would be violating the interface.





More information about the Python-list mailing list