forum

Home / DeveloperSection / Forums / Is a function an example of encapsulation?

Is a function an example of encapsulation?

Anonymous User352112-Jun-2013

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:

addOne(n)
    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?


Updated on 12-Jun-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By