23.05.2014 Views

Athena Developer Guide

Athena Developer Guide

Athena Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Athena</strong> Chapter 18 Framework packages, interfaces and libraries Version/Issue: 2.0.0<br />

18.3 Interfaces in Gaudi<br />

One of the main design choices at the architecture level in Gaudi was to favour abstract interfaces when<br />

building collaborations of various classes. This is the way we best decouple the client of a class from its<br />

real implementation.<br />

An abstract interface in C++ is a class where all the methods are pure virtual. We have defined some<br />

practical guidelines for defining interfaces. An example is shown in Listing 18.1:<br />

Listing 18.1 Example of an abstract interface (IService)<br />

1: // $Header: $<br />

2: #ifndef GAUDIKERNEL_ISERVICE_H<br />

3: #define GAUDIKERNEL_ISERVICE_H<br />

4:<br />

5: // Include files<br />

6: #include "GaudiKernel/IInterface.h"<br />

7: #include <br />

8:<br />

9: // Declaration of the interface ID. (id, major, minor)<br />

10: static const InterfaceID IID_IService(2, 1, 0);<br />

11:<br />

12: /** @class IService IService.h GaudiKernel/IService.h<br />

13:<br />

14: General service interface definition<br />

15:<br />

16: @author Pere Mato<br />

17: */<br />

18: class IService : virtual public IInterface {<br />

19: public:<br />

20: /// Retrieve name of the service<br />

21: virtual const std::string& name() const = 0;<br />

22: /// Retrieve ID of the Service. Not really used.<br />

23: virtual const IID& type() const = 0;<br />

24: /// Initilize Service<br />

25: virtual StatusCode initialize() = 0;<br />

26: /// Finalize Service<br />

27: virtual StatusCode finalize() = 0;<br />

28: /// Retrieve interface ID<br />

29: static const InterfaceID& interfaceID() { return IID_IService; }<br />

30: };<br />

31:<br />

32: #endif // GAUDIKERNEL_ISERVICE_H<br />

33:<br />

From this example we can make the following observations:<br />

page 160<br />

• Interface Naming. The name of the class has to start with capital “I” to denote that it is an<br />

interface.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!