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
291 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
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
2 votes
2 answers
377 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
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
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
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
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
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
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
1 vote
1 answer
266 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
2 votes
1 answer
167 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
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
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
1 vote
2 answers
246 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
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
0 votes
0 answers
53 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
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
2 votes
1 answer
454 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
2 votes
5 answers
958 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
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
  • 929
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
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
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
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
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

1
2 3 4 5