Skip to Main Content
Prefactoring
book

Prefactoring

by Ken Pugh
September 2005
Intermediate to advanced content levelIntermediate to advanced
240 pages
6h 28m
English
O'Reilly Media, Inc.
Content preview from Prefactoring

11.6. Paradigm Mismatch

Sometimes the paradigm of the underlying implementation does not match the paradigm of the interface you have created. Usually you can create an adapter that hides this difference. A dictionary holds pairs of keys with associated values. If you add a key that already exists, the value for the previous entry in the dictionary is overwritten silently. In other implementations, the duplication generates an error.

You might have created an interface that works one way. An implementation might work the other way. You can add logic to make that implementation work the other way. For example, if your interface assumed silent overwriting, the logic can check for the existence of the key and delete the current key before adding the new one.

You cannot adapt some paradigm mismatches in this manner. You might not be able to find an implementation that works in the paradigm of the interface you designed. In that case, you will have to rewrite the interface and redo the methods that depend upon it.[*]

[*] Eric M. Burke, a reviewer, noted that if you develop an interface without creating an implementation, you might create an interface that is impossible to implement in reality. Do not cast an interface in stone until you have developed and tested an implementation.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Understanding Unittest.Mock

Understanding Unittest.Mock

Mario Corchero
Java™ Performance

Java™ Performance

Charlie Hunt, Binu John

Publisher Resources

ISBN: 0596008740Supplemental ContentCatalog PageErrata