Hi all. My test question says:
If it is NOT universally held belief that objects must have both data & methods, argue why you might want to create a class that had only Methods.
... a class that had only Data.
Any inputs? thank you!!!
Hi all. My test question says:
If it is NOT universally held belief that objects must have both data & methods, argue why you might want to create a class that had only Methods.
... a class that had only Data.
Any inputs? thank you!!!
I could see I class with only methods if you inhereted another class with data from it. perhaps..
You write an interface class to enhance data hiding. Write the class that contains members to access the members of an implementation class. Define those members as friends of the implementation class and offer only the interface class to a user.
Though technically this isn't needed as you could define the interface to be public and the implementation methods to be private and are called but the public methods.
However, it could be a way of truly hiding data from another programmer by only allowing them use of the interface class and keeping the implementation class unknown and only used by the interface itself, not the programmer.
or
You derive a class from a base class and intend to use all of the members and methods defined in the base class with one or two extra methods but new members are not required.
-Prelude
My best code is written with the delete key.
aside from access if you don't need instantiation, you can also use namespaces.
hasafraggin shizigishin oppashigger...
I have created such a class... I created a string helper class to perform things such as...
void GetFileNameFromDirS( CString strFullPath )
void GetDirFromPath( CString strFullPath )
BOOL VerifyFileExtension( CString strFilename, CString strExtension)
...any way my point is that CString class is not intended to be inherited from.... No virtual destructor.... well you can do this through composition but which would require more work...
I have also created similar classes to handle certain routines such as exceptions...
consider this...
try{
....code ....
}
catch( CSomeException* e)
{
UtilException e;
e.DisplayExceptionMessage( e );
....handler code
e->Delete();
}
instead of
catch( CSomeException* e )
{
mystring msg;
mystring s;
for( int i = 0; i < e->GetErrorCount() ; i++)
{
s.Format( "Error Code %d,\nHelp Context: %d", e->m_nError, e->m_nContext);
smg += s;
smg += e->m_strDescription
smg += "\n";
}
DisplayMsg( smg );
}
which implemetation would you prefer?
zMan