dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Jan 7, 2008

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Hide Data and Implemention Details

Consider the following class:

#include "OtherData.h"

class MyClass {
  OtherData m_data;
public:
  bool func(OtherData data);
};
It seems as though this class hides its implementation details efficiently, but is actually doesn't! The user knows about the OtherData type and its requirements in its header file. To overcome this situation, you can do this:

class OtherData; // forward refernce

class MyClass {
  OtherData *m_pData;
public:
  bool func(const OtherData &data);
};
But what if you've got more than one field? Suppose you have a forward reference per data type. Now, you can define another extra class and store all the data there:

class DataHolder;

class MyClass {
  DataHolder *m_pDataHolder;
public:
  void func1(const OtherData1 &data);
  bool func2(const OtherData2 &data);
};
Now all the data are defined in DataHolder, which is then hidden efficiently.

Arman Sahakyan
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date