The encapsulation tag has no wiki summary.
3
votes
1answer
62 views
Should I write a wrapper within a manager object?
I have three classes that work together to do one function (from the perspective of the rest of my program). There is a little bit of set up between them, so, to make it easier for the rest of my ...
5
votes
2answers
158 views
Please explain object versioning in the nodejs module system
This question is about the persistance of variables across different modules in nodejs when they don't directly "require" each other, but do "require" a common ancestor.
It is also the generalised ...
0
votes
2answers
156 views
Is it useful to use encapsulation in dynamic typed, interpreted programming language?
For what I know, encapsulation is useful because:
if you use directly an attribute and change its type in a static typed language you have to change all the code that uses the class. On the ...
49
votes
12answers
4k views
Why is it a good idea for “lower” application layers not to be aware of “higher” ones?
In a typical (well-designed) MVC web app, the database is not aware of the model code, the model code is not aware of the controller code, and the controller code is not aware of the view code. (I ...
0
votes
2answers
55 views
Is it 'safe' to expect myClasses to agree not to only call package Scope methods from other Package scope methods?
The questions says it all, but a quick overview of the situation. I'm creating a Model which contains classes (all inherriting myObject) which have a large amount of interconnection. I want the ...
0
votes
0answers
61 views
How to ensure only one object for each item in my state exists?
I am refactoring an existing system heavily, merging some seperate programs and throwing in a proper MVC concept; working on the Model now.
My current system sits in the middle, one of a few views on ...
-1
votes
4answers
232 views
Immutable vs mutable object as returned parameter for class method [closed]
There is a class method (static method) in which I create and build some object. And for filling that object, I create it as mutable object.
My mutable object is a subclass of immutable object. So ...
4
votes
3answers
287 views
How important is encapsulation? [duplicate]
As a student in programming, I learned that encapsulation is one of the most important principles of object-oriented programming.
However, I only follow that principle when I feel like it suits my ...
5
votes
1answer
352 views
Is there a database programming language with encapsulation to prevent the injections?
One of things that annoys me about SQL is that it can't think in terms of objects and it's lack of encapsulation makes me constantly have to escape commands to prevent injections.
I want a database ...
2
votes
2answers
209 views
Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
Architecturally speaking, which is the preferable approach (and why)?
$validation_date = $users_repository->getUser($user_id)->validation_date;
Seems to violate Law of Demeter by accessing ...
31
votes
9answers
2k views
What should be allowed inside getters and setters?
I got into an interesting internet argument about getter and setter methods and encapsulation. Someone said that all they should do is an assignment (setters) or a variable access (getters) to keep ...
7
votes
5answers
397 views
How to TDD test that objects are being added to a collection if the collection is private?
Assume that I planned to write a class that worked something like this:
public class GameCharacter {
private Collection<CharacterEffect> _collection;
public void Add(CharacterEffect e) ...
5
votes
3answers
2k views
What is the use of Association, Aggregation and Composition (Encapsulation) in Classes
I have gone through lots of theories about what is encapsulation and the three techniques of implementing it, which are Association, Aggregation and Composition.
What i found is,
Encapsulation
...
7
votes
1answer
372 views
JavaScript objects and Crockford's The Good Parts
I've been thinking quite a bit about how to do OOP in JS, especially when it comes to encapsulation and inheritance, recently.
According to Crockford, classical is harmful because of new(), and both ...
3
votes
4answers
436 views
is 'protected' ever reasonable outside of virtual methods and destructors?
so, suppose you have some fields and methods marked protected (non-virtual). presumably, you did this because you didn't mark them public because you don't want some nincompoop to accidentally call ...
16
votes
9answers
1k views
Hiding away complexity with sub functions
I am having a discussion on code style, and it's starting to sound like a "matter of taste". I strongly believe otherwise, so I'm writing this to get your opinion and learn from your arguments for and ...
0
votes
1answer
103 views
How far should I expose this status enum?
I wrote a little app to manage an arbitrary series of tasks (e.g., call a SQL sproc and capture out-vars, run another app, run an SSIS package) with dependencies between tasks. Each task has a status ...
3
votes
3answers
355 views
When too much encapsulation was reached
Recently, I read a lot of good articles about how to do good encapsulation. And when I say "good encapsulation", I am not talking about hiding private fields with public properties; I am talking about ...
6
votes
6answers
538 views
How is encapsulation used for safety?
I am learning OOP. I have studied much about encapsulation but the more I read the more I became confused.
I understand we hide (by making private) data and expose it to user of class (other ...
1
vote
2answers
293 views
initial Class design: access modifiers and no-arg constructors
Context:
Student working through Class design in personal/side project for Summer. I've never written anything implemented by others or had to maintain code. Trying to maximize encapsulation and ...
9
votes
3answers
461 views
Do I suffer from encapsulation overuse?
I have noticed something in my code in various projects that seems like code smell to me and something bad to do, but I can't deal with it.
While trying to write "clean code" I tend to over-use ...
63
votes
11answers
12k views
Why do we need private variables?
Why do we need private variables in classes?
Every book on programming I've read says this is a private variable, this is how you define it but stops there.
The wording of these explanations always ...
6
votes
6answers
2k views
Are Get-Set methods a violation of Encapsulation? [duplicate]
Possible Duplicate:
When are Getters and Setters Justified
In an Object oriented framework, one believes there must be strict encapsulation. Hence, internal variables are not to be exposed ...
3
votes
3answers
1k views
Is JavaBeans a good example of encapsulation?
I'm trying to understand if JavaBeans is a good example of encapsulation. In my view, it's not as usually all the internal state is exposed through getters and setters.
A simple example is
public ...
5
votes
2answers
186 views
What defines an encapsulation properly?
I find the encapsulation concept a bit confusing. So far I have read that the members of the class should be private and any access to private members must be through getter and setter methods, which ...
21
votes
6answers
1k views
Using third-party libraries - always use a wrapper?
Most projects I am involved with use several open-source components. As a general principle, is it a good idea always to avoid binding all components of the code to the third-party libraries and ...
2
votes
4answers
257 views
Function locals: variable used in just one function
In OOP, static scope means the scope is linked to the class, and instance scope is linked to a specific instance of the class.
Some languages support static locals, which allow a value to be retained ...
3
votes
4answers
520 views
Using lambdas to improve encapsulation
Just as many people believe tenaciously in small functions, some people believe lambdas should only contain small code fragments.
An often overlooked advantage of lambdas however, is using them you ...
3
votes
4answers
350 views
How do you remember encapsulation types for effective use?
I've been attempting to learn C#.NET for the past month or so, and the array of ideas that seems to always trip me up is encapsulation. As this is one of the three pillars of OOP, I feel that I am ...
12
votes
6answers
768 views
Method chaining vs encapsulation
There is the classic OOP problem of method chaining vs "single-access-point" methods:
main.getA().getB().getC().transmogrify(x, y)
vs
main.getA().transmogrifyMyC(x, y)
The first seems to have ...
9
votes
7answers
1k views
Is it bad code smell if private method calls public one?
Is it bad code smell to call public method in private method of same object instance?
11
votes
4answers
509 views
Nested Classes: A useful tool or an encapsulation violation?
So I'm still on the fence as to whether or not I should be using these or not.
I feel its an extreme violation of encapsulation, however I find that I am able to achieve some degree of encapsulation ...