Most voted "builder" questions
Constructing object-oriented programming languages is a method called as soon as a new instance of the object is created. Such a method is usually responsible for allocating resources needed to function the object beyond the initial definition of the state variables (attributes). If the question is not about the "Constructor", do not use this tag, even if you are using the "Constructor" in your project.
Learn more…141 questions
Sort by count of
-
109
votes6
answers13840
viewsWhat good is a builder?
In general classes have constructor methods. What is the usefulness of the class constructor method? Why should we create it? It can work without it?
-
30
votes3
answers814
viewsHow and when to build an object in valid state?
Think of a large class, a complete customer registration for example. It has a huge amount of attributes in it. Many of them need to be initialized in the construction of the object in order for the…
-
21
votes6
answers1578
viewsIs it good practice to use constructors (or magic methods) in interfaces?
Well, I usually come using interfaces to define how some methods will be used. But to be honest, I’ve never seen anyone using interfaces to define contracts for a construtor. In a specific case I…
-
20
votes7
answers1682
viewsMake the class builder private?
When placing a constructor of a class in C# as private, get the following error: I would like to know the technical explanation for the reason of this error and whether there is any case of use of a…
-
19
votes1
answer25589
viewsWhen should I use __init__ in functions within classes?
For the book I am studying, in some moments the author uses __init__ as a first function of a class. This function (and others) always has self as one of the variables (something I haven’t yet…
-
15
votes2
answers1287
viewsWhat is the purpose of a static constructor?
I’ve always used builders as follows: public MinhaClasse() { //Algo ... } However I found that in C# it is possible to create a static constructor as follows: public class MinhaClasse { public…
-
15
votes1
answer170
viewsWhat is the use of "= delete" in the declaration of a constructor in C++?
I came across a builder declared as follows: State(const State& em) = delete; Does anyone know what the = delete at the end of the signature of the manufacturer?…
-
13
votes3
answers600
viewsWhat does this() do alone in the builder?
In the code: public Livro(Autor autor) { this(); this.autor = autor; } public Livro() { this.isbn = "000-00-00000-00-0"; }
-
12
votes2
answers13989
viewsWhat is the function of the super in a Java constructor?
I have a daughter class that inherits from another abstract class, and in the class builder I have the following: Public aluno(String nome, int idade){ super(nome,idade); } What is the function of…
-
12
votes4
answers1580
viewsIs this a common practice in object orientation?
In object orientation, one way to ensure encapsulation is to maintain the attributes of the private classes and modify their state via methods. In addition, to ensure the integrity of objects, it is…
-
11
votes1
answer1648
viewsDifference between method and constructor?
Reading a friend’s notes I came across the following statement: "method does not allocate space in memory". This statement is correct? It may not be the main difference between them, but it is…
-
11
votes1
answer5003
viewsIs it correct to create a constructor method in an abstract class?
If an abstract class cannot be instantiated, can creating a constructor method for this abstract class be regarded as good practice or not? If so, why are we creating the implementation of this…
-
10
votes2
answers6412
viewsWhat is the C++ copy builder for? How do I implement it?
I am a programmer Java and I am currently studying C++. In addition to the "normal" constructors (the standard constructor and the parameterized), C++ has a copy builder. I would like to know what…
-
10
votes1
answer152
viewsSealed class, with private constructor, versus Static class
When "studying" this class, I checked that it is sealed and has the private builder: public sealed class Interaction { /// <remarks> /// CA1053: Static holder types should not have public…
-
9
votes1
answer209
viewsStrange property initialization
While reading a tutorial on Entity Framework, I came across an example of code where there was a line that, for me, is unknown: Student stud = new Student() { StudentName = "New Student" }; I…
-
9
votes2
answers450
viewsStatic blocks, heritage and constructors in Java
Hello, during my studies in Java I came across the following question Given the code below: class Foo extends Goo { static { System.out.println("1"); } { System.out.println("2"); } public Foo() {…
-
9
votes1
answer207
viewsWhat is the difference between String name = "test" and String S4 = new String("Peter");
What’s the difference of assigning a value to a variable by creating an object and assigning Unboxing at a direct value? String s4 = new String("nome"); String nome = "nome";…
-
9
votes3
answers2573
viewsHow to use constructor overload in Typescript?
In languages with C#, for example, it is possible to use constructor overload as shown below: public class Teste{ public Teste(bool a, int b, string c){ } public Teste(bool a, int b){ } public…
-
8
votes1
answer1127
views -
8
votes3
answers157
viewsHow does field initialization work in constructors?
In the C# documentation it is written: If a class does not have a constructor, a default constructor is Automatically generated and default values are used to initialize the Object Fields That is,…
-
8
votes3
answers722
viewsInitialize private fields in the declaration or constructor?
I’m modeling a class that has a private list and an internal dependency on another object: public class Teste { private IList<string> Textos; private Teste2 Teste2; } I can initiate them in…
-
7
votes1
answer711
viewsHow does the class constructor statement in Qt work?
I work with C and a little bit of Assembly, in Atmel AVR microcontrollers. I’m trying to understand how the framework Qt extends C++. I created a new project with Qt Creator (Widgets), and generated…
-
7
votes2
answers8390
viewsWhere is the constructor of the class in Python?
Definition of Wikipedia. The builder is a method which is generally responsible for allocating the necessary resources to the operation of the object beyond the initial definition of the variables…
-
7
votes3
answers701
viewsWhat to do when the argument passed in the constructor is invalid?
I’m playing a card game in Java, and one of the classes is responsible for starting the game. In the builder, I get the number of players who will participate. I am doing the validation of the…
-
7
votes1
answer127
viewsWhat is the use / reason for the existence of new Object();?
While I was studying a little bit more about objects, I came across things like new String , new Number, etc.. I got curious, and I went to learn. I understood the functioning, despite having my…
-
6
votes1
answer272
viewsInitialization of data of a class
Is there a class initialization function for C++? In Lua, using the library classlib there is the function __init, and in Python as well. EX: require "classlib" Human = class(); function…
-
6
votes1
answer1230
viewsWhen using __constructor magic method or set and get
My doubt is with constructor relation, for example, I have a class with name, age. the correct is to use __construct to pass values to them or use set e get ?
-
6
votes2
answers509
viewsHow does the Table declaration instance work in Lua?
In object orientation, the class is usually created first and then the same. PHP example: class Test{ public function __construct() { // inicia as parada aqui } } $test = new Test; But in the Lua it…
-
6
votes2
answers733
viewsEmpty constructor without calling super()
When I do parameterized constructors, I create an empty constructor as well. In the empty constructor, should I always make the call to super()? Why? (Take into account, that my class is just a…
-
6
votes2
answers210
viewsWhat do builders mean by this?
This builder has a this, what it really means? public class HelpController : Controller { private const string ErrorViewName = "Error"; public HelpController() :…
-
6
votes1
answer292
viewsShould we create an empty constructor in Java?
It is good practice to always declare a builder, even if it is empty, for the class? I find it unnecessary, because the compiler automatically creates. I have seen people who always create and…
-
6
votes1
answer348
viewsDifference between constructor and function that returns literal object
What is the practical difference between me creating a construction function in this way: function construtora (nome, sobrenome) { this.nome = nome this.sobrenome = sobrenome } Or in this way:…
javascript function characteristic-language objects builderasked 4 years, 6 months ago Gustavo Paiva 173 -
6
votes3
answers425
viewsIs it mandatory to put the same attributes on different constructors?
I have these builders: //1st Constructor - Create bike with a new frame public Motociclo (String marca, String modelo, float peso, int robustez) { //Nivel 2 this.marca = validarMarca(marca);…
-
6
votes1
answer90
viewsUsing static factory methods instead of constructors
I’ve been doing some research on this subject after I read in Joshua Block’s book, Effective Java, Item 1, about the use of static factory methods rather than building builders. There in the text he…
-
6
votes2
answers155
viewsIs there any way to prevent the use of "new" in a Javascript function?
Assuming the function: function foo() { return 'something'; } It is possible to invoke it (abstract operation [[Call]]): // Invocando `foo`: foo(); In the above example, the string would be returned…
-
5
votes1
answer550
viewsCan one override in builders?
Is it possible to override in builders? For example: @Override public class main (String arg[]){}
-
5
votes3
answers1022
viewsYou’re a builder, right?
I’d like to understand why this class has two builders and why one of them has everything in it this and not separated as in the other. This changes something? Normal builder: public…
-
5
votes3
answers148
viewsVariable is not updated in constructor
I’m learning OO and venturing into PHP, only I came across something that I think in theory should work, but in practice does not work. <?php class Users{ public $name; public $idade; public…
-
5
votes3
answers177
viewsWhy does the this(6) command inside a constructor initialize the class array?
In the code: public class Lista{ int [] a; int n; public Lista(){ this(6); } public Lista(int i){ this.a = new int [i]; this.n = 0; } public static void main(String [] args){ Lista l = new Lista();…
-
5
votes1
answer143
viewsWhy are instance variables usually initialized in the constructor?
I have seen several codes where the instance variables of a class are initialized in the constructor, even I do it myself by watching others do it. But I never understood it. Logical that has the…
oop variables software-engineering builder initializationasked 5 years, 1 month ago NinjaTroll 1,752 -
5
votes1
answer185
viewsWhat is the difference between creating an object from the literal form or from a constructor function?
I wonder if it has any difference or relevance between the two forms below in the construction of an object: Create an object from the literal form: let pessoa = { nome: 'Pedro' };…
javascript characteristic-language objects builder prototypeasked 4 years, 8 months ago felipe cardozo 275 -
4
votes4
answers257
viewsUse of setters in the builder
I wonder if there’s any difference, semantically speaking, between these two builders: public Aluno(String n, float n1, float n2) { this.nome = n; this.setNota1(n1); this.setNota2(n2); } and public…
-
4
votes2
answers10606
viewsWays to instantiate an object and declare constructors
In C++ there are several ways to create a constructor and instantiate an object. But there are so many ways I’m confused by the difference of each. Assuming I have the following class: using…
-
4
votes2
answers607
viewsWhat is the difference between initializing a constructor or doing attribution within the constructor?
What is the difference between the two examples below? I should also assign the value within the constructor in this class even if I initialized? example 1: class sof{ int teste; public: sof(int t)…
-
4
votes1
answer344
viewsDifferences in constructors using property vs field (field)
namespace WMB.CieloB { internal class FuncoesCielo { internal FuncoesCielo(int iDC, Boleto boleto) { IDCliente = iDC; this.boleto = boleto; } public int IDCliente { get; set; } internal Transaction…
-
4
votes1
answer350
viewsHow to initialize an array in this constructor?
I’m trying to initialize a array with 0, however the compiler is generating error, I know I can initialize as well: Constructor() : Value1(0), Value2(0), Initialized(false), vSh(false) { Name[100] =…
-
4
votes1
answer71
viewsWhat is the difference between two code snippets with and without a constructor?
I’m having trouble understanding what a constructor does. Does it initialize a variable so it’s not null? If yes, this would not be solved easily by doing what is written in the second code snippet?…
-
4
votes1
answer76
viewsCreation of objects in Javascript
Let’s say we want to create an object called Retângulo (if desired, with properties such as length, width, perimeter and area). As shown in the next diagram (created based on the information present…
-
3
votes1
answer2607
viewsCan I declare a builder in the child classes when the mother class is abstract and already has a builder?
My question is this: If I can declare a constructor in a class abstract and also in the child classes. And also how to access their values. For example: abstract class Animal { private $nome;…
-
3
votes2
answers12630
viewsHow does Java Builder Heritage work?
In Java when one class inherits from another it is necessary to initialize the constructor of the parent class, right? using the super() and passing to this super() the parameters the parent…