| | |
Types of methods in C++?
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2007
Posts: 7
Reputation:
Solved Threads: 0
There are three main type of methods in C++ I read somewhere but I forgot where exactly and in which article did I read that. But it is something like Access methods, Modify methods and the third one.. I think it is managerial method. But not really sure. Can any one tell me what are those three methods with some explanation about it. If not, please do provide me a link from where I can learn more about them. I wish i could have bookmarked that article when I read that. I now really cant find any other place on the WWW which talks about these. Please help guys. :-|
..... When you want it the most there is no easy way out, When you ready to go and your heart left in doubt, Dont give up on your faith, Victory comes to those who believe it and That's the way it is!...
Well, let me try to help if I can.
First of all consider a class like this:
An accessor method is used when another method needs the value contained in a private data member of the class. An example of this would be
Modify methods would be a method that modifies a private data member inside a class. An example of this would be
Well, the whole goal of object-oriented programming is to make classes relatively independant objects. In other words, if you suddenly want
Finally... managerial functions. I've never heard such a description of them before, so I'm only guessing. I suppose it's a function that manages an object, such as constructors/destructors (memory management), or something such as a function that does more than simply modify a value in an object.
For more information on these topics, I suggest you visit the following sites:
First of all consider a class like this:
C++ Syntax (Toggle Plain Text)
class myClass { private: int data; public: myClass() {}; ~myClass() {}; int getData() {return data;} void setData(int newData) {data=newData;} void calculateRoot(int amount) {data=sqrt(amount);} };
An accessor method is used when another method needs the value contained in a private data member of the class. An example of this would be
myClass::getData(), because all it does is return the value of the data. This type of function is useful for making a read-only variable.Modify methods would be a method that modifies a private data member inside a class. An example of this would be
myClass::setData(), because it changes the value of data. Now, you may be wondering why you would use a public member function to modify a private member. Why not just make the data member public?Well, the whole goal of object-oriented programming is to make classes relatively independant objects. In other words, if you suddenly want
data to equal the value+1, the only things you should have to change is within the class itself. By changing the setter method, the whole thing is changed. If you had manually set the values from other classes, you would suddenly find yourself facing a whole ton of coding. Another good example of this is if you need to change data types in a class.Finally... managerial functions. I've never heard such a description of them before, so I'm only guessing. I suppose it's a function that manages an object, such as constructors/destructors (memory management), or something such as a function that does more than simply modify a value in an object.
For more information on these topics, I suggest you visit the following sites:
- http://en.wikipedia.org/wiki/Method_(computer_science)
- http://www.stepwise.com/Articles/Tec...-06-11.01.html (this is Objective-C, but the concepts presented are identical)
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
The "modify methods" or "setter methods" are more popularly or formally known as "Mutator functions".
I agree with Joey in that the third category is not a formal one. I can make a pretty guess that the methods which are neither Accessors nor Mutators fall under the category of so called Managerial functions. For eg. the functions which perform the task of setting the parameters for the environment in which it is invoked.
I agree with Joey in that the third category is not a formal one. I can make a pretty guess that the methods which are neither Accessors nor Mutators fall under the category of so called Managerial functions. For eg. the functions which perform the task of setting the parameters for the environment in which it is invoked.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
- Inventory Control Database Design (Costing Methods) (Database Design)
- another newbie with alot of redhat and apache server Q'S (Linux Servers and Apache)
- DNS record types (PHP)
- Array Values not found in Methods (Java)
- C++ Data Types (C++)
- win XP issues (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Vector of vectors & magic square issues
- Next Thread: documenting your code
Views: 7481 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






