Monday, March 15, 2010

Windows Mobile 7

Finally it has been disclosed by Charlie Kindel, Microsoft Partner Group Program Manager for the Windows Phone Application Platform & Developer Experience, that the existing applications of Windows Mobile will not run on newly launched mobile OS by Microsoft.

Kindel says in his blog post on March 4:
The Windows Phone 7 Series developer platform is as different as the new user experience. It’s fresh. It’s pure. And it’s powerful.
The new Windows Phone 7 Operating system will also support the following platforms which are already the key GIANTS by Microsoft to develop other platforms and Windows for PCs is also one of them.
  • NET
  • Silverlight
  • XNA platform
  • Microsoft’s developer tools
  • Web 2.0 standards

In the post Charlie Kindel clearly describes:
One result of this is previous Windows mobile applications will not run on Windows Phone 7 Series.
To be clear, we will continue to work with our partners to deliver new devices based on Windows Mobile 6.5 and will support those products for many years to come, so it’s not as though one line ends as soon as the other begins.
After reading the whole post one thing which I concluded is that Microsoft Company wants to have a lot of apps and games for Windows Phone 7 series. In fact their main goal will be to beat the Mobile Stores of Apple and Google which are the largest stores of apps and games for iphone and android based mobiles.

Microsoft will reveal more details about apps, games and platform for Window Phone 7 at the Mix 10 conference which will start on March 15 in Las Vegas.

Friday, November 13, 2009

Accessing the Private Member outside the Class (without Friend)

The following article discusses the dangers of returning a reference to private data of a class.

First, it is shown how a reference to private data member is returned from a member function and then the consequences of doing so are discussed.

Returning a Reference to Private Data in a Class :

The example below shows how a reference is returned to a private data member in a class :

class ATestClass
{
private:
int x ; // these are private
char y; // data members of the class

public:
AtestClass () // default constructor of class
{
--------------------------------
---body of constructor----
--------------------------------
}

int &retReference() // this is the bad function that returns reference to private member x
{
x = 10;
return x ; // dangerous !! (reference to private data x is returned)
}
};

The catch in the above code snippet is that the function retReference() can be used as an lvalue in any assignment statement. The code snippet below shows how :

int main()
{
ATestClass testObject; // creates an object of ATestClass
testObject.retReference() ; // sets the value of x in testObject as 10
int z = testObject.retReference() ; // z becomes 10
testObject.retReference() = 20 ; // dangerous !! the private data member of ATestClass is directly accessed and modified !
int &a = testObject.retReference() ; //again dangerous !! a becomes a reference to private data x in object testObject
a = 100 ; // dangerous !! private data member x in object testObject

return 0 ;

}

In the above code snippet, the statement

testObject.retReference() = 20 ;
is a perfectly valid C++ statement because the function retReference() returns a reference to int x, and hence it can be used as an lvalue in any assignment statement. Thus, even if data member x is private in class ATestClass, it is directly accessed through object testObject and is modified.

Similarly, the statement

int &a = testObject.retReference();
declares a as a reference to private data member x in testObject. Then, the following statement
a = 100 ;
uses a as an alias (reference) to private data x and modifies its value.

This breaks-down the data hiding and encapsulation features of a class and defeats the purpose of Object OrientedProgramming in the following ways :

  • The private data in the class no longer remain “private” as they can be directly accessed through any variable that is a reference to the private data.
  • The encapsulation feature is also destroyed as data and its functions are no longer bound together. Data can be accessed without the help of the member functions of the class.

Thus, we have seen how a simple thing such as returning references to private data members of a class destroy Object Oriented Programming concepts. This is an example of a poor programming practice, and should be avoided.