Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 136311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:55:42+00:00 2026-05-11T06:55:42+00:00

By putting functionality into a function, does that alone constitute an example of encapsulation

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:55:42+00:00Added an answer on May 11, 2026 at 6:55 am

    Perhaps you are confusing abstraction with encapsulation, which is understood in the broader context of object orientation.

    Encapsulation properly includes all three of the following:

    • Abstraction
    • Implementation Hiding
    • Division of Responsibility

    Abstraction is only one component of encapsulation. In your example you have abstracted the adding functionality from the main body of code in which it once resided. You do this by identifying some commonality in the code – recognizing a concept (addition) over a specific case (adding the number one to the variable n). Because of this ability, abstraction makes an encapsulated component – a method or an object – reusable.

    Equally important to the notion of encapsulation is the idea of implementation hiding. This is why encapsulation is discussed in the arena of object orientation. Implementation hiding protects an object from its users and vice versa. In OO, you do this by presenting an interface of public methods to the users of your object, while the implementation of the object takes place inside private methods.

    This serves two benefits. First, by limiting access to your object, you avoid a situation where users of the object can leave the object in an invalid state. Second, from the user’s perspective, when they use your object they are only loosely coupled to it – if you change your implementation later on, they are not impacted.

    Finally, division of responsility – in the broader context of an OO design – is something that must be considered to address encapsulation properly. It’s no use encapsulating a random collection of functions – responsibility needs to be cleanly and logically defined so that there is as little overlap or ambiguity as possible. For example, if we have a Toilet object we will want to wall off its domain of responsibilities from our Kitchen object.

    In a limited sense, though, you are correct that a function, let’s say, ‘modularizes’ some functionality by abstracting it. But, as I’ve said, ‘encapsulation’ as a term is understood in the broader context of object orientation to apply to a form of modularization that meets the three criteria listed above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 159k
  • Answers 159k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer THe files from a "Content" folder will not be deployed… May 12, 2026 at 11:23 am
  • Editorial Team
    Editorial Team added an answer Kernow provides a nice interface for working with Saxon/Xerces2 to… May 12, 2026 at 11:23 am
  • Editorial Team
    Editorial Team added an answer Cocoa delegates are used to accomplish inversion of control and… May 12, 2026 at 11:23 am

Related Questions

If I have a simple class setup like this: class MyClass { private string
I'm writing an eclipse editor plugin for a custom file format and want to
I'm onto a real head scratcher here ... and it appears to be one
Short version: Is it easy/feasible/possible to program modal window in Flash (AS3)? Is there

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.