Most voted "encapsulation" questions
In object orientation, encapsulation is the mechanism to restrict access to some of the components of the object or a design principle that encourages the dissociation of the implementation details. Encapsulation protects direct access to the attributes of an instance outside the class where they were declared. This protection consists of using more restrictive access methods on the attributes defined in the class.
Learn more…46 questions
Sort by count of
-
51
votes4
answers3366
viewsAre getters and setters an illusion of encapsulation?
It is common to teach that it is right to leave the class attributes private and create getters and setters for them, all because of the encapsulation. Isn’t that the same thing as making everything…
-
30
votes2
answers5203
viewsMethods and properties in C# - advantages and disadvantages
In C# we have properties with getters and setters, which facilitates the insertion and reading of data in an object when some logic should be performed. In other languages, such as Java these tasks…
-
16
votes3
answers3152
viewsWhen to use Setters and Getters?
I’m studying OOP and in the encapsulation part I had a question about when to use getters and setters, besides being able to validate the parameter passed, what is the usefulness of using? I could…
-
12
votes1
answer231
viewsWhen is it useful to separate state of behavior?
In object orientation there is the concept of encapsulation: meet in the same state class and the functions operating in that state. But there are situations where it is useful to separate state and…
oop software-engineering ddd software-project encapsulationasked 6 years, 5 months ago Piovezan 15,850 -
10
votes2
answers1800
viewsWhat is the relationship between encapsulation and polymorphism?
A few days ago, I was talking to a friend about Java, and asked what part of the story they were studying. Then he replied that they were starting inheritance studies. As they were too late, I asked…
-
9
votes1
answer234
viewsEncapsulation and Java Access Modifiers
A very simple question: Given that class: public class User { private String nome; //get/set public boolean fazQualquerCoisa(){ **duvida**.equals("algumacoisa"); } } Within the method did All() I…
-
8
votes2
answers335
viewsHow to customize the getter in Kotlin?
When we create a variable of type val, in the case of Java, only the getter relative to it. Different when a type variable is created var, in which the getter and setter. See below for an example:…
-
7
votes1
answer146
viewsCan Observer be considered encapsulation break?
Observer use of abstraction and interfaces. Let’s assume that a Observer "assists" the state changes of certain classe and informs them to another external agent, we may consider this a…
-
7
votes1
answer275
viewsI could not understand very well the encapsulation in the POO
I took a course in programming logic and now I’m doing logic OO, but it’s come to the encapsulation part and I’m having a little bit of trouble understanding. What it would be and how it’s used?…
-
7
votes1
answer223
viewsWhy hide the implementation of a class?
This is the concept I’ve worked hard to understand, but I’ve never fully achieved. I’ll take this excerpt from a Deitel book to illustrate: It is a better software engineering define member…
-
6
votes1
answer279
viewsObject-oriented PHP encapsulation
I have two models User and Post. When editing a post, I want to know if the user is the author of post (the post has an attribute user_id) to authorize the edition. If I have a method within the…
-
5
votes1
answer387
viewsHow to send/encapsulate a file in a . apk to use in the app installation?
I have a file . xls that would like to encapsulate next to apk so that when installing the app it uses that file to popular a database. How to do?
-
5
votes1
answer302
viewsWhat happens in real life in a developer environment if the programmer does not encapsulate an attribute?
The programmer João went there and created a class Cliente and the attribute public double saldo and the method Sacar() public also. What’s wrong with leaving the attribute double saldo, after all…
oop software-engineering encapsulation getters-setters privateasked 7 years, 7 months ago user3671786 55 -
5
votes2
answers337
viewsReal example of the use of encapsulation
I researched about encapsulation, I even read some topics here, but I haven’t seen a real example of how to use it in a way that can show me its advantages, what problems it avoids. I have an…
-
4
votes4
answers7150
viewsIn inheritance with private attributes, does not the daughter class take its attributes from the mother class?
The devmedia article says the modifier private does not give access to its attributes in its child classes. It has a table with modifiers. In inheritance with private attributes, the daughter class…
-
4
votes3
answers122
viewsWhy does the code print 0 instead of 5?
Why does this code print 0 instead of 5? class B { private int b; public int getB() { return b; } public void setB(int b) { b=b; } } class A { public static void main (String[] args) { B b = new…
-
4
votes3
answers173
viewsWhy is it not (easily) possible to hide private members?
Implementation concealment is one of the keys to good modern software engineering, and crucial in code reuse. Why then, in c++ is it not possible to hide the private data implementation? Since these…
-
4
votes4
answers569
viewsIn Object Orientation, does an inheritance violate encapsulation?
According to the book Design Standards written by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, make a statement: "...inheritance violates the encapsulation." Below is the paragraph…
-
4
votes0
answers51
viewsWhy is it recommended to encapsulate in POO?
Would you have small examples to show me? To understand why? I’m studying PHP, but it can be in any language.
-
4
votes3
answers218
viewsPublic field X property
I have a string defined as "name" initially it is as private. string nome; In case I assign the methods get/set, and to stay in the pattern I change the initial letter to uppercase, getting: string…
-
4
votes3
answers280
viewsHow do I block access to setting parameters in a class?
import math class Circulo(): def __init__(self): super() self.__raio = None def get_perimetro(self): return 2 * math.pi * self.raio def get_area(self): return math.pi * self.raio ** 2 @property def…
-
3
votes3
answers162
viewsRelationship Have-one in C#?
I tried to do a have-one relationship in C# and I’m not getting it and I don’t even know if it’s recommended to do. Follow my error code: System.Nullreferenceexception Undefined object reference for…
-
3
votes1
answer421
viewsHow do I access the contents of a Jtextfield?
In a java project no connection to Database where we have only the layers Model, View and Controller, what would be the most appropriate way to catch a String which is contained in a JTextField of a…
-
3
votes2
answers514
viewsHow to return a pure Json (without XML encapsulation) using webservice in c#
I’m with a webservice running locally, which conducts queries directly in a database through a string type parameter. Follow the outcome of the consultation: The second moment I have an application…
-
3
votes1
answer299
viewsPrinciples of Encapsulation
I am studying for the Java Programmer SE 7 I certification exam. I use Selftest Kaplan (recommended by Oracle itself). I came across the following question: (I will leave everything in English on…
-
3
votes1
answer56
viewsDefining the chained methods of a method
Let’s say I have the following class: class animal{ private $animal; private $som; function gato(){ $this->animal = 'gato'; return $this; } function cachorro(){ $this->animal = 'cachorro';…
-
3
votes1
answer176
viewsPass parameters with properties c#
I’m putting together a script of fighters, the category I want to be a private method and that it is according to the weight that the user type, but I’m not able to mix these two attributes in the…
-
2
votes1
answer628
viewsHow to use variables in a location outside the scope where they were created?
I have the following code: public class TracoActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);…
-
2
votes1
answer436
viewsEncapsulation, Functions - String function call
I’m having a problem checking if a certain function exists. Code - Similar. if(jQuery){ (function(jQuery){ jQuery.extend(jQuery.fn, { exemplo: function(o){ var chartError = false; function…
-
2
votes2
answers557
viewsQuestion about initialized attributes in the constructor in Java
package Livraria3; public class Livro { private String nome; private String descricao; private double valor; private String isbn; Autor autor; public Livro(Autor autor) { this.autor = autor;…
-
2
votes1
answer93
viewsIs the implementation of an interface part of the encapsulation or heritage pillar?
The implementation of an interface is part of the pillar of encapsulation or heritage of the POO? As far as I know encapsulation disrespects the visibility of the attributes and methods contained in…
-
2
votes2
answers135
viewsDoubt about access modifiers and polymorphism
I have a very beginner question about polymorphism/access modifiers in Java. I’d like to find out why a certain phenomenon occurs in my code. Below is an example of classes: Class Pai: public class…
-
2
votes1
answer64
viewsDifference between property declaration in C#
I’m studying C#, very beginner, and I came across something, the course I’m doing has video lessons from 2015, and it passes me to create a class with attributes and properties like this:…
-
2
votes1
answer67
viewsInstantiate a class with private attributes
How can I take the attributes of the person class and instantiate them in the medical class and then display it? The doctor and the patient are people and both have class attributes Pessoa. I left…
-
1
votes1
answer185
viewsClass declaration in C#
What other access levels can I declare a class in C# besides public and private. I found these levels in the microsoft website: protected internal protected internal…
-
1
votes1
answer251
viewsHow to reference instance variable with the same name as a local variable in C++?
In C++, how can I reference an instance variable that has the same name as a global variable? For example, in a set method of the following class: class Person { private: string name; public: void…
-
1
votes1
answer1846
viewsJava Academic System
Hello. I need help to build a Java program with the following specifications: 1) Read, from the user, the following items: Name(String), Age(int), gender(char[M or F]), telephone(String),…
-
1
votes0
answers117
viewsComparison Methodthe Comparable interface allows encapsulation breaking?
The Student class has its private attributes and to access or modify them it is necessary to use the get and set methods. In addition, the Student class implements the Comparable interface. class…
-
1
votes1
answer138
viewsHow to determine the level of access of the elements of a class?
This is a question of the Secitec 2018 competition for the position of computer teacher. I appealed to this question because there are no qualifiers, but access modifiers such as: private, protected…
-
1
votes2
answers113
viewsEncapsulation of functions
Below is an example of using a function passed as a parameter to another function: def gera_nums(): lista = [] for c in range(0, randint(1, 15)): lista.append(randint(0, 100)) return lista def…
-
0
votes1
answer1048
viewsEncapsulation and Get and Set methods
I am continuing my studies in object-oriented Java programming. I am currently studying encapsulation and methods get and set and I came across the following exercise: Encapsulate the value…
-
0
votes1
answer60
viewsPrivate encapsulation in inheritance
The class SuperSuper has an attribute of type private defined whole. Any specialization of the class SuperSuper may reset the encapsulation to public and your data is automatically converted? public…
-
0
votes1
answer141
viewsPackaging in Kotlin
I am starting my studies in Kotlin and am trying to solve the following problem: Create a class to represent a person, with private attributes of name, date of birth and height. Create the necessary…
-
-1
votes1
answer3097
viewsHow do I calculate Euclidean distance
I have a class Ponto: public class Ponto { public int x; public int y; public int getX() { return x; } public void setX(int x) { this.x = x; } public int getY() { return y; } public void setY(int y)…
-
-1
votes0
answers22
views(Python) Using a Private attribute in a subclass
My wish is to validate my IF in class B using a private attribute that was done in class A. Nothing more than that, I am aware of some methods to verify an anonymous attribute but still I could not,…
-
-4
votes1
answer72
viewsHow to pass the array from a method to Another method using interface
I want to create a program that uses interfaces to create a vector class with name and size and have the methods below: <> +Definirnometamanhovetor +PreencherVetorCriadoInformandoPosicaoValor…