Skip to main content

Questions tagged [encapsulation]

Encapsulation is the principle of bundling software elements in a way to hide implementation details and to expose only a known interface.

Filter by
Sorted by
Tagged with
0 votes
6 answers
300 views

In a certain program I would like to have three objects, say, a, b, and c, with c being a shared private member (sub-object) of a and b. The data between the three objects shall only go this way: a &...
Alexey's user avatar
  • 958
0 votes
3 answers
157 views

A service interface allows a service layer to support backwards compatibility. As long as the different versions of the API are still supported, then changes can be added to the newer versions of the ...
Vaccano's user avatar
  • 4,077
5 votes
1 answer
576 views

Using assimp I've created a function to load 3D models and it does everything I need and I don't plan to use another library or write something custom, however, I am curious how techniques such as ...
Konjointed's user avatar
0 votes
2 answers
209 views

I have a project where there is a primary, high-level, opaque struct with many functions that operate on it. Maybe I am simulating a CPU. How might the corresponding source code be organized? One way ...
Ana Nimbus's user avatar
2 votes
2 answers
379 views

This question is language/framework agnostic. EDIT: The comments and answers have highlighted how different languages approach events differently, which made me realize this question isn't really ...
Michael Haddad's user avatar
1 vote
6 answers
553 views

I have a question about encapsulation and I read these two topic (this & this) but I got more confused. I've been reading Head First Object-Oriented Analysis and Design book and I'm trying to ...
Mehdi's user avatar
  • 29
2 votes
2 answers
2k views

Many times while writing MVVM apps in C# I've come across this sort of problem where I need to expose the model in a view model so that I can get it in another view model and do something with it. ...
aelsi2's user avatar
  • 31
9 votes
4 answers
3k views

I'm writing this library in which the user can provide custom code defining the algorithm used for finding an optimal solution. In the papers that I have read, the targeted user thinks in terms of ...
Mehdi Charife's user avatar
1 vote
2 answers
255 views

Let's say that I have a Parent class and a Child class, Parent relies on Child to perform, say, some network request: class Parent { ... public init(){ const child = new Child(); const ...
Tizio Fittizio's user avatar
0 votes
2 answers
383 views

I was submitting this code in Java to an AI tool that checks for OOPS modeling and it says that this class is breaking encapsulation, although it did not gave any reason why. The objective is to store ...
Ayush Kumar's user avatar
0 votes
0 answers
91 views

When working with functions that run a few short "procedures" in sequence that are not used anywhere else and it makes sense to keep it all inline, in a single function, a large part of the ...
Jake1234's user avatar
  • 129
4 votes
4 answers
840 views

As I am learning OOP principles, I know that it is always good practice to hide the inner workings of classes so that the end user can't access or break them. I understand why this is important. The ...
Caleb Shank's user avatar
1 vote
2 answers
5k views

I have a single *.h file. This file contains a single (more to come) function declaration. Now the implementation of that file is very complex. the corresponding *.cpp contains several function ...
user avatar
3 votes
5 answers
393 views

I'm learning to make games with OOP and there's something I don't understand. What I can see is that the more I add methods to a class, the less it becomes reusable and flexible. For example, if we ...
Voko's user avatar
  • 233
0 votes
1 answer
217 views

Assume a low-level API is provided without source code (e.g. DirectX). The API provides a virtualization of hardware resources (GPU, CPU, audio card, etc.), which enables the user to call hardware-...
chckx592's user avatar
9 votes
4 answers
3k views

Protected visibility in languages like C++, Java or PHP is a strange beast: it makes fields and methods accessible in subclasses, but not in code completely outside the class. It strikes me as ...
user3840170's user avatar
2 votes
3 answers
1k views

I've been trying to get a better understanding of OOP (I'm not the biggest fan of it, but I still want to understand it). One of the core principles of OOP is encapsulation - you're supposed to ...
Scotty Jamison's user avatar
0 votes
1 answer
275 views

Module A contains a gap buffer for manipulating text and some associated methods. Relevant to this question is the dependency on a Module B, used for syntax highlighting of text. Module A also ...
user avatar
1 vote
1 answer
267 views

I'm struggling to test functionality in a class where the class has to be in a certain state for the functionality to work, but the class cannot be put directly into a given state by design, to ...
gotube's user avatar
  • 127
0 votes
2 answers
102 views

I have worked on a library which processed data through multiple steps. It was written in R, a dynamic programming language where one could just add fields to existing “objects”, which were just ...
Martin Ueding's user avatar
2 votes
1 answer
168 views

The other day, I came across this question on StackOverflow. In short, the user who asked the question wanted to extend a class from a third-party library to implement the Codable protocol, but ...
TallChuck's user avatar
  • 152
-3 votes
2 answers
153 views

I am building a chess - related application, and I want to use a pre-compiled program called Stockfish as my chess engine. I am wondering what is the best practice to encapsulate the usage of the ...
Aviv Aviv's user avatar
  • 117
0 votes
2 answers
287 views

I'm having an issue with dependencies in a C# app that I'm creating. I have an assembly for my authentication process, and a separate assembly for starting up the main program once authentication is ...
Adam B's user avatar
  • 1,660
0 votes
3 answers
354 views

Encapsulation is the hiding of an implementation in OOP the way I understand it. I searched on Google and I was thinking of trying to write a program to test, but my tests would only happen at run ...
NewYorkSup's user avatar
4 votes
4 answers
1k views

I've run into the following situation multiple times, and in every case have struggled with the naming. I want a class to force its children to implement a method, but I want the parent class to be ...
Adam B's user avatar
  • 1,660
2 votes
1 answer
5k views

When developing a shared library in C, it is common to separate the "public" headers from the "private" headers. The public headers contain all the functions and types that are ...
Woodrow Barlow's user avatar
1 vote
2 answers
247 views

Suppose I have two "modules", A, and B (I'm choosing not to use classes, because you generally can't create an instance of a module, which makes this question simpler). These modules contain ...
taylorthurlow's user avatar
0 votes
1 answer
118 views

I have looked at several examples for implementations of Momento on the web. I wonder if it is correct to retrieve the status of Originator, since this is much more accurate, up-to-date and reliable? ...
celsowm's user avatar
  • 253
2 votes
2 answers
854 views

C++ only supports single dynamic dispatch methods. Indeed, the following program: #include <iostream> struct Shape { virtual void overlap(Shape* y) { std::cout << "Shape, Shape\n&...
Géry Ogam's user avatar
3 votes
3 answers
2k views

I was going through a question and here the answer says that Encapsulation is being violated class car { int speed; public : int* getSpeed() { return &speed; } }; int ...
arqam's user avatar
  • 149
0 votes
0 answers
54 views

note: This is of couse about software-architecture/design-principles, but as no architecture is completely detached from its language, please note that the language i am using is C++. I am using an ...
LeonTheProfessional's user avatar
1 vote
1 answer
379 views

I have no experience with C (only C++ and higher level languages). Right now I have tried and failed to find general guidelines on how to write good C code in a way that allows to separate the ...
Adomas Baliuka's user avatar
0 votes
2 answers
2k views

So I'm writing a network simulator in C++ as part of a university project. Right now, I have a class structure that looks something like: //includes type aliases #include "GlobalTypes.h" //main body ...
Connor Carr's user avatar
0 votes
2 answers
139 views

I have an application. It needs to send emails. We've all been there, done that, got the t-shirt. I've got an IEmailMessage interface: public interface IEmailMessage { string From { get; } ...
Ian Kemp's user avatar
  • 398
2 votes
1 answer
455 views

I would like to create a state machine. Each State would have its run method, and, according to some logic would then set a next state. Option 1: If each state is responsible for determining a next ...
Gulzar's user avatar
  • 1,240
0 votes
4 answers
592 views

In another question on this site, asking to clarify the open closed principle, @Kate Gregory answered this. I'm interested in this part specifically: Imagine you wrote an Invoice class that works ...
Unimportant's user avatar
2 votes
5 answers
962 views

I'm struggling to find good ways to split up classes without exposing private data. Most articles I read about SRP seem to ignore how the new classes that take on the separated responsibilities access ...
Unimportant's user avatar
38 votes
7 answers
9k views

Encapsulation In object-oriented programming (OOP), encapsulation refers to the bundling of data with the methods that operate on that data, or the restricting of direct access to some of an ...
Christopher Trotter's user avatar
13 votes
3 answers
6k views

I made the following diagram to show a typical separation of concerns as typically taught - Here ClassA indirectly uses ClassB via the ISomeInterface, of course ensuring it doesn't know ClassB exists, ...
user4779's user avatar
  • 939
2 votes
4 answers
2k views

I am in the process of refining my code to adhere more to my current understanding of the Single Responsibility Principle (SRP). Originally, I had a class called Animal that had a set of methods and ...
MagerBlutooth's user avatar
4 votes
2 answers
3k views

I am a Java dev for almost all of my programming (at least in the workplace) but I do some Unity for fun on the side. I have used C# properties many times and they are convenient to still provide ...
JaredSK74's user avatar
3 votes
2 answers
2k views

I am trying to implement some of the principles laid out in Clean Code by Robert C. Martin. I had a class that was heavily suffering from the ordering problem. I have solved most of this by ...
MSOACC's user avatar
  • 965
9 votes
4 answers
1k views

I was reading this page, about when getters/setters are justified, and the OP gave the following code sample: class Fridge { int cheese; void set_cheese(int _cheese) { cheese = _cheese; } ...
QueenSvetlana's user avatar
-2 votes
2 answers
580 views

I learn C# and try to understand the logic between static and Constructor right now. One thing I need ask you about an example which I will give at below. (please ignore the quality of code or how ...
Melih Cinar's user avatar
0 votes
1 answer
103 views

Let's say I have a stacked 2 layer app (High Layer (HL) and Low Layer (LL)) that is implemented in C. HL defines a few #defines. HL calls a LL function with a parameter that takes values of the #...
Satrapes's user avatar
2 votes
4 answers
306 views

I understand the principles behind opaque data types, encapsulation, information hiding, etc. in theory: preventing alteration to parts of a program can prevent people from accidentally messing it up, ...
Nicholas's user avatar
  • 163
0 votes
4 answers
396 views

This is a simple scenario in an office with employees and their manager. In this scenario, both managers and employees have a name attribute. Only the manager can change his own name Only the ...
Susantha7's user avatar
  • 406
1 vote
4 answers
391 views

Assume you have a library in which every function is public. Sooner or later developers who use your library will come up with a stable pattern of usage. In that terms external information of how ...
Eugene's user avatar
  • 43
3 votes
4 answers
2k views

I work on refactoring an Java application based on a CAST audit. One of the criterion says that To respect OO encapsulation concepts, private fields should always be accessed through accessors So ...
The Once-ler's user avatar
4 votes
6 answers
2k views

This question is related to How should an `Employee` class be designed? In the above question, to uniquely identify an employee, each Employee object has an id field as shown below class Employee { ...
Susantha7's user avatar
  • 406

1
2 3 4 5