The Artima Developer Community
Sponsored Link

Human Centric Development
Interface Implementations Not Just From Factories
by Ken Pugh
January 9, 2007
Summary
Interface implementations are not just found using factories. You can use compile or link time alterable implementations.

Advertisement

Scott Meyers recently sent me some comments on “Interface-Oriented Design”. He described a few concepts and ideas that the book should have covered in more detail.

One of the points he made regards something that I’ve used in the past, but did not really think about when writing the book. An interface does not have to be represented with an “interface” keyword or equivalent and then implemented by code using “implements” in Java or ":" in C++.

You can establish an interface as a set of methods, along with a test framework that clarifies and enforces the requirements for the methods. You then create different source code modules that provide that same set of methods. At either compile or link time, you specify which module to use for a particular version of the executable. A particular implementation of the interface can be compiled using conditional compilation. Alternatively, a different object module can be linked into the executable.

For example, you might have different types of hard disks that you are using in different versions of an embedded system. You first establish a standard hard disk interface. Using the appropriate source code modules, you implement the hard disk interface for each specific type of hard disk. Now these modules do not use the keyword “implement” or equivalent. They just provide all the methods in the interface.

At link time, you incorporate the module corresponding to the hard disk that you are using on a particular piece of equipment. Using directly linked modules eliminates the overhead of virtual function calls.

In addition, if you are using C++, you include the corresponding module header file in the code that uses the interface. If there were inline functions in that header, you would get a performance benefit.

Talk Back!

Have an opinion? Readers have already posted 6 comments about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Ken Pugh adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

Ken Pugh of Pugh-Killeen Associates (www.pughkilleen.com) consults, trains, and mentors on technology topics ranging from Object-Oriented Design to Linux/Unix to the system development process. He has served clients from London to Sydney. When not computing, he enjoys snowboarding, windsurfing, biking, and hiking the Appalachian Trail.

This weblog entry is Copyright © 2007 Ken Pugh. All rights reserved.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us