Symbian3/PDK/Source/GUID-F94CEC6D-C602-550F-9B12-856493F3C509.dita
changeset 1 25a17d01db0c
child 3 46218c8b8afa
equal deleted inserted replaced
0:89d6a7a84779 1:25a17d01db0c
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE task
       
    11   PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
       
    12 <task xml:lang="en" id="GUID-F94CEC6D-C602-550F-9B12-856493F3C509"><title>Implementing an Interface </title><shortdesc>An interface implementation is a single unit of functionality that is instantiated through the interface definition. An implementation is created by deriving a class from the interface definition, and implementing its functions. An interface implementation actually provides the services defined by the interface. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody><steps id="GUID-7A342564-DF90-57AD-874C-164C7BE66B9A"><step id="GUID-C213F154-EEA1-503B-A184-AB76FF1DECE2"><cmd>Derive a class from the interface definition. </cmd> </step> <step id="GUID-C72498E7-82F6-598F-A1D7-613A89E9D4A2"><cmd>Implement the object creation functions like <codeph>NewL()</codeph> or <codeph>ConstructL()</codeph> for the derived class. </cmd> </step> <step id="GUID-0C9777EC-5998-5A83-9C13-3E45875BB748"><cmd>Call the appropiate <xref href="GUID-1344F049-81C4-3D17-AF46-8B5584680ADB.dita#GUID-1344F049-81C4-3D17-AF46-8B5584680ADB/GUID-C7F147AC-6D77-3169-AAB4-B27262B4333B"><apiname>REComSession::CreateImplementationL()</apiname></xref> function to instantiate an interface implementation that satisfies the specified interface. </cmd> </step> <step id="GUID-6379343D-1990-59ED-919E-AEB7185C1A44"><cmd>Implement the pure virtual functions defined by the interface definition, to provide required services to clients. </cmd> </step> </steps> <example id="GUID-8CE792E8-0E17-5660-A1E0-DF10E83B73D4"><title>Creating an interface implementation example</title> <p>The following code depicts an example segment of the interface definition class derived from <xref href="GUID-067293BF-B28C-3CEC-92F4-1351A795EA7F.dita"><apiname>CActive</apiname></xref>. </p> <codeblock id="GUID-D988EFE2-4F4E-5A5A-B1E8-1859A3FB8198" xml:space="preserve">class CExampleInterfaceDefinition : public CActive
       
    13     {
       
    14 public:
       
    15     // Wraps ECom object instantiation
       
    16     static CExampleInterfaceDefinition* NewL();
       
    17     // Wraps ECom object destruction 
       
    18     virtual ~CExampleInterfaceDefinition();
       
    19     // Interface service 
       
    20     virtual void DoMethodL() = 0;
       
    21 ...
       
    22 private:
       
    23     // Instance identifier key or UID.
       
    24     TUid iDtor_ID_Key;
       
    25     };</codeblock> <p>The following code depicts a class derived from the interface definition CExampleInterfaceDefinition. </p> <codeblock id="GUID-1F88C6F8-2486-5EDB-A7D3-0E15CB0C7633" xml:space="preserve">class CExampleIntImplementation : public CExampleInterfaceDefinition
       
    26     {
       
    27 public:
       
    28     // Two-phase constructor
       
    29     static CExampleIntImplementation* NewL();
       
    30     // Destructor
       
    31     ~CExampleIntImplementation();
       
    32     // Implement the required methods from CExampleInterfaceDefinition 
       
    33     void DoMethodL();
       
    34 
       
    35 private:
       
    36     void ConstructL();
       
    37     };</codeblock> <p>The following code depicts the implementation of the object creation functions and virtual functions in CExampleInterfaceDefinition. </p> <codeblock id="GUID-B1356DF4-C838-5DF8-AE43-5F503780E5DE" xml:space="preserve">CExampleIntImplementation* CExampleIntImplementation::NewL()
       
    38 {
       
    39     CExampleIntImplementaion self = new (ELeave) CExampleIntImplmentation();
       
    40     CleanupStack::PushL(self);
       
    41     self-&gt;ConstructL();
       
    42     CleanupStack::Pop();
       
    43     return self;
       
    44 }
       
    45 
       
    46 void CExampleIntImplementation::ConstructL()
       
    47 {
       
    48 // specific implementation
       
    49 }
       
    50 CExampleIntImplementation::~CExampleIntImplementation()
       
    51 {
       
    52 }
       
    53     ~CExampleIntImplementation();
       
    54 
       
    55 void CExampleIntImplementation::DoMethodL()
       
    56 {
       
    57     // specific implementation of the DoMetholdL()
       
    58 }
       
    59 
       
    60 </codeblock> </example> </taskbody></task>