Is a function an example of encapsulation?

Total Post:183

Points:1285

OOPS 
 3112  View(s)
Ratings:
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:

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?

  1. 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

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.