Questions tagged [information-hiding]

Information hiding is the ability to prevent certain aspects of a class or software component from being accessible to its clients, using either programming language features (like private variables) or an explicit exporting policy.

Information hiding is defined as a language construct that facilitates the bundling of data with the methods (or other functions) operating on that data. Now that also happens to be the 2nd definitive notion of Encapsulation. However, since the primary definition of Encapsulation is, "a language mechanism for restricting access to some of the object's components," the two are inherently separate.

Also see

130 questions
7
votes
5 answers

Is it better to pass an *interface* or an *object* as a parameter to a function?

I'm trying to convince a colleague that a function should take an interface as a parameter, and not the object itself. I think small objects can be fine to pass across, but for large ones I would give them an interface and just pass the i/f over,…
5
votes
2 answers

How to hide a datum from everyone but class T

I want a type A that will yield its hidden datum to an object of type T but hide the datum from everyone else. My C++ compiler happens to be GCC 4.4, but that shouldn't matter. Why won't this work? #include template class A…
thb
  • 11,861
  • 3
  • 35
  • 63
5
votes
5 answers

Information Hiding vs. Hidden Dependencies

What are some common best practices in procedure (or function, module, etc.) design for balancing the desire for information hiding and an appropriate level of abstraction in the procedure's interface with the problems inherent in introducing…
4
votes
2 answers

Breaking encapsulation and information hiding in Java

Consider the following snippet. package breakoop; public class BreakOOP { public static class A{ private int a; } public static class B extends A{ public int f(){ return super.a; } } public…
Igor Ševo
  • 5,251
  • 3
  • 27
  • 66
4
votes
2 answers

Swift: access level between `private` and `internal`?

In my Swift code, I often use the private modifier to limit the visibility of helper classes. For example, in one file, I'll have a GridController and a GridControllerModel. The GridController (the UI) should be accessible to the rest of the…
Bill
  • 38,492
  • 24
  • 114
  • 205
4
votes
1 answer

How to change or camouflage address bar url?

We have a site dedicated to people suffering domestic violence. Our priority is for the people using the site to be safe and avoid them being caught by their "violentator". Everything is almost sorted out but there is one thing that still doesn't…
sitavn
  • 41
  • 3
4
votes
8 answers

Where do you put unit tests for private methods?

Where do you put unit tests for private functions in C# classes? An article in Wikipedia suggests: Putting tests in the same class as the members they're testing Using partial classes Personally, neither of these methods seem appropriate, and I…
Jonathan
  • 29,612
  • 37
  • 126
  • 201
4
votes
2 answers

Practical example Encapsulation vs Information Hiding vs Abstraction vs Data Hiding in Java

I know there are lots of post regarding this question which has theoretical explanation with real time examples.These OOPs terms are very simple but more confusing for beginners like me. But I am expecting here not a definition and real time…
Prashant Shilimkar
  • 7,156
  • 11
  • 45
  • 83
4
votes
2 answers

Is it okay for decorators to access private members of a class?

I'm writing a class that parses HTML in order to provide an interface to a profile on a webpage. It looks something like this: class Profile(BeautifulSoup): def __init__(self, page_source): super().__init__(page_source) def…
Patrick Collins
  • 9,307
  • 4
  • 23
  • 60
4
votes
2 answers

How encapsulation is broken while accepting default Serialization?

I often hear people saying that Serialization breaks encapsulation and this loss of encapsulation can be somewhat minimized by providing custom serialization. Can someone provide a concrete example that justifies the loss of encapsulation due to…
Geek
  • 23,609
  • 39
  • 133
  • 212
4
votes
3 answers

How to use private Java classes for effective API design

I am writing my first "API jar" that will be open source library and used by (possibly) other developers. I've read Joshua Block's thesis on effective API design, and one of the things he talks about - that I never would have thought of otherwise -…
IAmYourFaja
  • 50,141
  • 159
  • 435
  • 728
4
votes
7 answers

Private functions of a class accessible?

I have been trying to learn C++ for some time now. Recently I came across the following piece of code: #include using namespace std; class Point { private: double x_, y_; public: Point(double x, double y){ …
Starburst
  • 61
  • 1
  • 6
3
votes
2 answers

In this case, how to modularize program as well as achieving information hiding?

I created two classes "DEVICE_s" and "DEVICE_SET_s" as following: Device_Manager.h typedef struct DEVICE_s DEVICE_s; typedef struct DEVICE_SET_s DEVICE_SET_s; Device_Manager.c struct DEVICE_s { uint32_t IP; TYPE_e Type; METHOD_e…
Andy Lin
  • 381
  • 2
  • 14
3
votes
2 answers

Information hiding and functional programming coding style

I was developing a simple class, called Simulator, that applies a list of Simulations to a certain input. For each input the simulations can produce an output or not, based on some conditions that the input has to fulfill with respect to each…
3
votes
4 answers

Reducing the visibility of a static method

I know that a child cannot reduce the visibility of a non-static method and I understand why it is so. I've read however that "static method can be hidden through its redeclaration". I however do not understand how this could be achieved in Java. Is…
infoholic_anonymous
  • 929
  • 3
  • 12
  • 29
1
2
3
8 9