IT Community - Software Programming, Web Development and Technical Support

Creating a Complete Class

This is a discussion on Creating a Complete Class within the C and C++ Programming forums, part of the Software Development category; When you are trying to use or reuse a class in C++, there is nothing quite so frustrating as finding ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-16-2007, 08:59 AM
ragavraj ragavraj is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 92
ragavraj is on a distinguished road
Default Creating a Complete Class

When you are trying to use or reuse a class in C++, there is nothing
quite so frustrating as finding that the method that you need is
not implemented in that class, or that the method does not work
properly when you try to use it in the environment you are using. The reason
for this is usually that the programmer who developed the class did
not create a Complete class — but what, exactly, does it mean to create
one? That’s a good question, and this technique will try to answer it.
To do its job, a Complete class must follow a list of specific rules. These
rules, in their correct order, are as follows:

1. The class must implement a void constructor.
2. The class must implement a copy constructor.
3. The class must implement a virtual destructor.
4. The class must implement a get method for each data element defined
in the class.
5. The class must implement a set method for each data element defined
in the class.
6. The class must implement a clone method so it can make a copy of
itself.
7. The class must implement an assignment operator.
If you create a class that follows all these rules, you have likely created a
Complete class, one that will be reused by programmers over and over
again. This will save you time and effort in not having to reinvent the
wheel each time that type of code needs to be used in a project.


Please note that having a set method for a class implies strongly that
the set method will check for invalid values. Also, if you have pointers
in your class, you should make sure that you initialize them to NULL,
copy them properly, and destroy them when they are done. A set
method for a pointer ought to take into account that it is acceptable
to set the pointer to NULL and not have any memory leaks.


Thanks
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
DBCC Commands Complete List for SQL Server vadivelanshanmugam Database Support 7 03-12-2008 09:45 PM
Debug class and Trace class simplesabita Software Testing 3 08-18-2007 12:30 AM
Is there any way to use keyPressed method of Canvas class in Form class? bluesky Mobile Software Development 1 07-25-2007 06:02 AM
What is super class sub class in error? santoshmalvi Software Testing 1 04-16-2007 01:20 AM
Complete Java Game nhoj Java Programming 0 04-05-2007 01:21 PM


All times are GMT -7. The time now is 06:39 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0