EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

#Previous question #Index of COM/DCOM Questions #Next question

Aggregation

COM aggregation is an object oritented design concept to take the instance of external/third party object and use it for the purpose of the co-classes in the server. This is a reuse of existing implementation without implementing by own. Here in the below example we are using a CExtEngine external class in CVehicle. We are not implemening CExtEngine but CVehicle is using its functionality by creating one instance.

class CExtEngine
{
public:
  static CExtEngine * CreateInstance();
  virtual int Release() = 0;
  virtual int PowerOff() = 0;
  virtual int SetGear(int nGear) = 0;
  virtual int Drive() = 0;
  virtual int Reverse() = 0;

};
class  CVehicle
{

private:
    int m_nGear;
    CExtEngine *m_pEngine;
public:
    CVehicle()
    {
    m_nGrear = GEAR_NUTRAL;
    m_pEngine = CExtEngine::CreateInstance();
    
    }
    ~CVehicle()
    {
    m_nGrear = GEAR_NUTRAL;
    m_pEngine->PowerOff();
    m_pEngine->Release();
    m_pEngine = NULL;
    
    }
    void ChangeGear(int nGear)
    {
      m_nGrear = nGear;
      if(m_nGrear == GEAR_NUTRAL)
      {
        m_pEngine->PowerOff();
      }
      else {
        m_pEngine->SetGear(m_nGrear);
      }
    }
    int Drive()
    {
      m_pEngine->SetGear(GEAR_DRIVE);
      return m_pEngine->Drive();
      
    }
    int Reverse()
    {
      m_pEngine->SetGear(GEAR_DRIVE);
      return m_pEngine->Reverse();
      
    }
};

Containment

Containment also an object oritented design concept by including or inheriting an module in the class. This very similar to aggregation but here we implement the module and reuse it by creating a member object in the derived class or inheriting the base class to derived class.

class CEngine
{

private:
    int m_nGear;
public:
    CEngine()
    {
    m_nGrear = GEAR_NUTRAL;
    
    }
    int Drive()
    {
      
    }
    int Reverse()
    {
      
    }
};

class CVehicle : public CEngine 
{

private:

public:
    CVehicle(): CEngine()
    {
      
    }
    ~CVehicle()
    {
    
    }

};

You have viewed 1 page out of 66. Your COM/DCOM learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

# COM DCOM Interview Questions and Answers :: ALL Interview .com
# COM DCOM - COM DCOM Interview Questions
# COM interview questions | TechInterviews
# COM Interview Questions - CodeProject
# Com Dcom Interview Questions - Com and Dcom in Asp Net
# ATL Interview Questions and Answers :: ALL Interview .com
# ActiveX Interview Questions and Answers :: ALL Interview .com

* #1 webmaster Mon 28 Apr/2014 01:48:12(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.

Regards,
Webmaster

Your message goes here:

Name:Guest
Email:anonymous@unknown.com
My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
 
Note:
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.