Is a function an example of encapsulation?

Total Post:183

 2863  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?

  1. Post:100

    Re: Is a function an example of encapsulation?

    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.

      Modified On Mar-30-2018 02:27:13 AM



Enter your email address here always to be updated. We promise not to spam!