Thread: Data vs do you argue this qtion?

  1. #1

    Data vs do you argue this qtion?

    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!!!

  2. #2
    I could see I class with only methods if you inhereted another class with data from it. perhaps..

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    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.


    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.

    My best code is written with the delete key.

  4. #4
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    aside from access if you don't need instantiation, you can also use namespaces.
    hasafraggin shizigishin oppashigger...

  5. #5
    Registered User
    Join Date
    Aug 2001

    class with no data

    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...
    ....code ....
    catch( CSomeException* e)
    UtilException e;
    e.DisplayExceptionMessage( e );
    ....handler code

    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?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Robust method for storing data outside of a program
    By goatslayer in forum C++ Programming
    Replies: 17
    Last Post: 09-19-2007, 03:08 PM
  3. Reading a file with Courier New characters
    By Noam in forum C Programming
    Replies: 3
    Last Post: 07-07-2006, 09:29 AM
  4. Dynamic data members?
    By confusalot in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2005, 11:15 AM
  5. All u wanted to know about data types&more
    By SAMSAM in forum Windows Programming
    Replies: 6
    Last Post: 03-11-2003, 03:22 PM