Home > DeveloperSection > Forums > Is a function an example of encapsulation?
Ankita Pandey
Ankita Pandey

Total Post:183

Posted on    June-12-2013 1:31 AM


 1 Reply(s)
 2520  View(s)
Rate this:

By putting functionality into a function, does that alone constitute an example of encapsulation or do you need to use objects to have encapsulation?

I'm trying to understand the concept of encapsulation. What I thought was if I go from something like this:

n = n + 1

which is executed out in the wild as part of a big body of code and then I take that, and put it in a function such as this one, then I have encapsulated that addition logic in a method:


    n = n + 1

    return n

Or is it more the case that it is only encapsulation if I am hiding the details of addOne from the outside world - like if it is an object method and I use an access modifier of private/protected?

Vijay Shukla

Total Post:100

Posted on    June-12-2013 7:56 AM

Hello Ankita Pandey!

Encapsulation is a process in which attributes(data member) and behavior(member function) of a objects in combined together as a single entity refer as class.

Don't want to miss updates? Please click the below button!

Follow MindStick