Sharing! What gained.

Jul 9, 2015

C++ Modifiers and Accessors


Modifier and Accessors, In common English are refer to modify something from its old state to new state and accessor means to give a person  access to something .Now in OOP (Object Oriented Programming) as we all know that we cannot use private members outside of class  this allow the user to use the private Datatype outside of class i.e in Main function(Main Body) of program indirectly.In a way that we can modify the values of those Private Datatypes outside of the class and we can output those values of Private Datatype out of the class.

Modifies

Now the question is how do we use Modifiers?
Simple, We made a function in the class whose private Datatype are to be used the function will be a simple function which we used to make in POP(Procedural Oriented Programming) and we will pass it a perimeter of Same Datatype to that Private Datatype to which we want to assign a value ,Then in body of the function we will assign that parameter to the Private Datatype of class that we want to use,After making the Object in main body we will call it through member access operator(.),Example will make it more clear.

Accessors

Now the question is how do we use and make accessors?
Accessors are even more simpler than Modifier we will make a function in the same class Whose Private Datatype we want to output, Then we will write an output statement in the body of function that we made , We will give the Identifier(Name of Datatype) of the private Datatype of the class that we want to output the following example will make it more clear.




Share this Post!

3 comments:

  1. Hello Zerk, Can you share any experience of using accessors and mutator in your program or project.

    ReplyDelete
  2. I have used it in several of my OOP projects,Like when I was making this "Student Record system", I declared the Datatypes and to assign them values I used the concept of Accessor and Modifiers(mutator),Apart from that its used in almost every code that you are going to writer in C++ using OOP concepts .

    ReplyDelete