Questions tagged [encapsulation]

In OOP, mechanism for restricting access to some of the object's components or a design principle encouraging decoupling from implementation details.

In a programming language encapsulation is used to refer to one of two related but distinct notions, and sometimes to the combination thereof:

  • A language mechanism for restricting access to some of the object's components.
  • A language construct that facilitates the bundling of data with the methods (or other functions) operating on that data.

Some programming language researchers and academics use the first meaning alone or in combination with the second as a distinguishing feature of object oriented programming, while other programming languages which provide lexical closures view encapsulation as a feature of the language orthogonal to object orientation.

The second definition is motivated by the fact that in many OOP languages hiding of components is not automatic or can be overridden; thus, information hiding is defined as a separate notion by those who prefer the second definition.

(quote from Wikipedia)

2032 questions
0
votes
0 answers

Show E-Mail as HTML Content

I search possible ways to display other HTML Code inside HTML Website, than doesn't conflict layout of the website. I found follwing ways on the net: IFrame (insecure, dangerous) Helpful Link Google Caja (Iframe, Server Side needed) Helpful…
Gerlando Caldara
  • 313
  • 1
  • 3
  • 10
0
votes
2 answers

Java: Button Encapsulation

So what I am trying to accomplish is to add ActionListener to a button which is defined in another class, without breaking encapsulation of this button. My GUI class: public class GUI extends JFrame { private JButton button; public GUI…
0
votes
2 answers

Standard containers encapsulation and range-based for loops

I'm designing a class which has two standard vectors as members. I would like to be able to use range-based for loops on the vector elements and I came up with this solution #include #include using namespace std; class MyClass…
carlo
  • 325
  • 1
  • 4
  • 12
0
votes
1 answer

A general query about django / javascript patterns and how to best organize/encapsualte

I have been warned that this is subjective and likely to be closed, but seems an essential question that I haven't seen addressed. I am currently coding webapps in Django and using a bit of JavaScript to do this and that. Naturally, I sometimes…
normonics
  • 191
  • 1
  • 7
0
votes
2 answers

Pythonic way to encapsulate method arguments of a class

Objects of my class A are similar to network connections, i.e. characterized by a handle per connection opened. That is, one calls different methods with a handle (a particular connection) as argument. My class A (python 2.7) looks like: class…
José
  • 1
0
votes
1 answer

How to implement validation with encapsulation

Please first see original question: Encapsulation in JavaScript with getter and setter @Jacob Thanks Jacob! That is great information.I am not quite sure how that solution works but placing the methods into that return clause works well. Here is my…
Rich
  • 35
  • 4
0
votes
3 answers

Encapuslate code that might or might not return a value

Let's say I have some piece of code that I want to reuse. This piece of code has the property that it either returns something or that it modifies some data but does not return anything. Because of that, I cannot make it a usual method (return type…
Kjara
  • 2,504
  • 15
  • 42
0
votes
3 answers

How to implement Factory for production code, dependency injection for Unit Tests

I want to give a caller of my class ability to choose provider by name, instead of passing the provider concrete class as standard DI recommends. It will allow to hide actual implementation details from client, still giving control which…
0
votes
1 answer

How to wrap "with-usable" object into class?

Suppose we have an object, which is intended to be used with with: with somefunction() as f: ... f.somemethod() Now I want to use it within class, to make object available full lifetime of class instance. In constructor I would write class…
Dims
  • 47,675
  • 117
  • 331
  • 600
0
votes
0 answers

Python getter gives AttributeError object has no attribute

I have to use the setter part of Python and I thought I understood but I guess I don't. I have tried to change the parameters of the object, I have been wrestling with the declarations in the initialization and stuff, but I just don't seem to be…
mtjiran
  • 292
  • 1
  • 2
  • 12
0
votes
1 answer

Java Encapsulation with arrays

So I have two classes one is called bag the other is called TestBag. The goal is to ask the user what they want: to add or remove, and show what they have in the cart. I'm kinda new to encapsulation, and I don't know how to get the user input and…
Glorksnork
  • 67
  • 1
  • 9
0
votes
1 answer

What are the metrics for encapsulation?

What are the closest metrics (or even exact metrics) that you can use to check encapsulation? Braking encapsulation in Object-Oriented code is one the worst thing you can do to your project (if not THE worst). Many (if not all) of the programming…
Belun
  • 4,151
  • 7
  • 34
  • 51
0
votes
3 answers

Encapsulation: why the name keySet in java

In java to get all the keys in a map we can use the method keySet. But I was wondering why the method name is not just keys? isn't the name Set leaks details about the implementation? As per my understanding Java is statically typed language and…
CodeYogi
  • 1,352
  • 1
  • 18
  • 41
0
votes
1 answer

OCaml use signature defined outside functor to limit visibility into produced module

I'm trying to write a functor that takes a pair of ordered things and produces another ordered thing (with ordering defined lexicographically). However, I want the resulting "ordered type" to be abstract, rather than an OCaml tuple. This is easy…
Greg Nisbet
  • 6,710
  • 3
  • 25
  • 65
0
votes
0 answers

How could private modifier guard the encapsulation of an object, not class?

In Java, I understand why we define the instance field as private in some class, that is for protecting the encapsulation of a class. However, I am confused about the instance of that class. See below: public class DotaHero { private String…
Oliver
  • 147
  • 9
1 2 3
99
100