Interface Design by Bill Venners
Use interface extension to decouple services or restrict the semantic contract
Advertisement
|
Interface Design |
Contents |
Previous |
Next
Service Decoupling
-
Guideline: Use
interface
extension to decouple services or restrict the semantic contract.
-
Can decouple services from one another, to encourage clients code be as
type-precise as possible
-
List
adds void add(int, Object)
, Object get(int)
,
ListIterator listIterator()
, etc...
-
Can also build trees upwards:
Restricting Semantics
-
Can't just slap interfaces together -- semantics must be compatible (though not necessarily identical)
-
Subinterface semantics can be more concrete (more restrictive) than superinterface semantics
-
Set
doesn't declare any new methods compared to Collection
-
Semantic contract of
boolean add(Object)
:
Collection
- Ensures that this collection contains the specified element.
Set
- Adds the specified element to this set if it is not already present.