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.
211 questions
0
votes
6
answers
291
views
Design pattern for exposing different parts of interface to different entities
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 &...
5
votes
1
answer
576
views
Confused on how abstraction and encapsulation is helpful
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 ...
2
votes
2
answers
377
views
Handling parents events from child component, in a props down events up approach
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 ...
2
votes
2
answers
2k
views
MVVM: How and should I expose view models' models to other view models?
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.
...
1
vote
2
answers
255
views
Where to determine different behaviour for a child class with feature flags
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 ...
0
votes
0
answers
91
views
Lambdas vs scope blocks for encapsulation in c++
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 ...
1
vote
2
answers
5k
views
Recommended way of hiding implementation details?
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 ...
0
votes
1
answer
217
views
How far can one debug a low-level API in closed-source environments?
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-...
2
votes
3
answers
1k
views
How do you achieve encapsulation while "separating view and business logic"?
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 ...
1
vote
1
answer
266
views
How to test functionality that requires a certain internal state?
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 ...
2
votes
1
answer
167
views
Guidelines for using extensions in Swift
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 ...
0
votes
2
answers
287
views
Where to put files (interfaces) that link two independent assemblies: Authentication and Main Program
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 ...
4
votes
4
answers
1k
views
How name public method that relays to abstract methods of its children (c#)
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 ...
1
vote
2
answers
246
views
How does one choose where to place logic which converts data between two formats/representations?
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 ...
2
votes
2
answers
854
views
Are multiple dynamic dispatch methods possible?
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&...
0
votes
0
answers
53
views
Use debug-functionality without breaking architecture
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 ...
0
votes
2
answers
2k
views
Should I use a class with only static members to encapsulate my program?
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 ...
2
votes
1
answer
454
views
State Machine: what object is responsible for state transfer?
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 ...
2
votes
5
answers
958
views
Splitting class responsibilities without exposing private data
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 ...
13
votes
3
answers
6k
views
How does encapsulation actually work?
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, ...
4
votes
2
answers
3k
views
Is there anything wrong with writing getter/setter methods in C#? [duplicate]
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 ...
9
votes
4
answers
1k
views
Can renaming a method preserve encapsulation?
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; }
...
0
votes
1
answer
103
views
Sharing #define's between higher and lower layer. Where should shared types go? [closed]
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 #...
0
votes
4
answers
396
views
methods that has only behavior and not manage class state, is that violation of encapsulation
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 ...
3
votes
4
answers
2k
views
Should a class provide public mutators for all its private fields?
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 ...