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 ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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 |
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |