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

How could I restrict access between javascript files included in a webpage?

I have been learning about encapsulation in Javascript with the module pattern. I want to give access to specific js files. From what I understand, it is only possible to restrict access to everything and give access to everything, is this…
0
votes
0 answers

How to encapsulate a custom MediaRecorder in Android Kotlin?

I am new to Kotlin programming. I use the following code to record audio as part of my AudioRecorderDialogFragment: fun startVoiceRecorder(voiceFilename: String) { if (mAudioRecorder == null) { // We don't have an AudioRecorder, so we…
CEO tech4lifeapps
  • 885
  • 1
  • 12
  • 31
0
votes
1 answer

What are the different ways of accessing an ArrayList from a method?

I'm working on some homework programs and I'm required to do stuff in Java using functional programming principles as much as possible. These are the important bits of a program that receives a list of numbers and prints the even ones: public…
0
votes
2 answers

confusion about abstraction and encapsulation

Can anyone tell me with examples abstraction and encapsulation and difference between them?
Sandy
  • 1
0
votes
2 answers

Does python support private variables?

I have heard that "“Private” instance variables that cannot be accessed except from inside an object don’t exist in Python : as seen here However, we can create private variables using getter and setter methods in python as seen below class…
user2225190
  • 547
  • 1
  • 6
  • 18
0
votes
1 answer

Cannot assign this. variables in object prototypes

I'm currently studying javascript prototypes and I'm quite confused on how it really works. I have this code snippet and it works perfectly function Message(msg){ this.msg =msg; } Message.prototype = { constructor:Message, display:…
cattarantadoughan
  • 509
  • 1
  • 6
  • 15
0
votes
2 answers

Overloading operator in class and returning reference to private value

Example class I'm using: class Vector { double val[3]; public: double & operator [] (const unsigned int & index) {return this->val[index];}; } Then I call it like: Vector Example; Example[0]=5; Is using operator overloading like this correct or it…
Ava
  • 818
  • 10
  • 18
0
votes
0 answers

Python Strategy Design Pattern

I apologize for my bad English. I need your help. I just bring strategy design pattern, I have understood the pattern with a simple example, but the implementation in my project is very confusing for me, maybe you can help me. I have for example…
PsyOrc
  • 47
  • 8
0
votes
1 answer

Is making an instance variable private only benefits the subclasses?

I'm a beginner. I'm currently learning about OOP. From what I understand, making instance variables private means it is accessible within the class only. So you need to make set and get methods to have access into it for subclasses. But I can…
thox
  • 129
  • 4
  • 13
0
votes
0 answers

Laravel Notifications Can't Query Properties From Listener

I'm subscribing to notification events using a listener as described in the docs. My issue is, when I try to query the notification, for example, using $event->notification it appears to not work. This is because a print_r reveals all the properties…
Summer Developer
  • 2,056
  • 7
  • 31
  • 68
0
votes
1 answer

How to hide function implementation from caller in nodejs

I am exporting a js module via module.exports. The caller function requires this module and calls the exported functions. Code looks something likes this: file1.js module.exports = { Info: showInfo } function showInfo(param1, callback) { …
0
votes
0 answers

CSS styling in angular emulated view encapsulation

due to style problems with with VIEWENCAPSULATION.NONE in my angular component I switched to .EMULATED Now, I am unable to make the simplest CSS changes. The styles saved in the components css file, NOT in the global css file.. Eg, in a mat-tab…
baouss
  • 1,312
  • 1
  • 22
  • 52
0
votes
2 answers

How to prevent accessing delegate methods for other classes?

For the purpose of making a "more encapsulated" app, I am trying to specify the access levels for my view controllers properties/methods. But the issue is when trying to private a datasource/delegate method, I am getting a compile-time error…
Ahmad F
  • 30,560
  • 17
  • 97
  • 143
0
votes
5 answers

Should I use a private property/field with a public getter method or directly use a public property for proper encapsulation?

For proper encapsulation, should I use a private property with a manual getter method like in Java: public class Foo { private int Prop { get; set; } public Foo { Prop = 1; } public int GetProp() { return…
Piorrro33
  • 19
  • 8
0
votes
1 answer

How to access public members of elements in an encapsulated vector?

class obj1{ public: void do(){} void some(){} void stuff(){} }; class obj2{ public: void nowDo(){} void someOther(){} void things(){} }; template class structure{ public: /* access public members of Ts's…
1 2 3
99
100