Types of methods in C++?

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2007
Posts: 7
Reputation: dahlia_06 is an unknown quantity at this point 
Solved Threads: 0
dahlia_06 dahlia_06 is offline Offline
Newbie Poster

Types of methods in C++?

 
0
  #1
Mar 2nd, 2007
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!...
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Types of methods in C++?

 
0
  #2
Mar 2nd, 2007
Well, let me try to help if I can.

First of all consider a class like this:
  1. class myClass {
  2. private:
  3. int data;
  4. public:
  5. myClass() {};
  6. ~myClass() {};
  7. int getData() {return data;}
  8. void setData(int newData) {data=newData;}
  9. void calculateRoot(int amount) {data=sqrt(amount);}
  10. };

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:
"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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,652
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Types of methods in C++?

 
0
  #3
Mar 2nd, 2007
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 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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 7481 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC