Most voted "oop" questions
Object orientation is a paradigm of analysis, design and programming of software systems based on the composition and interaction between several units of software called objects.
Learn more…1,456 questions
Sort by count of
-
2
votes2
answers684
viewsTransform object to Dict in python
Good team, blz ? So, I started to study python now and wanted a help from you on the following question: I need a class that receives two distinct arrays (words and key) and relates all elements of…
-
2
votes1
answer409
viewsWhat is the "super()" operator for in Javascript?
What is the operator’s functionality super() which lies within the method constructor?
-
2
votes2
answers143
viewsOverload of C++ operators, is the auxiliary variable necessary in this case?
I am studying for the book Introduction to Object-Oriented Programming with C++ (Antonio Mendes da Silva Filho), and implemented an example of it as follows: #include <iostream> using…
-
2
votes1
answer74
viewsInstantiating a class "x" from another class "y" inherited by the class "x"
If I have a class Diretor who inherits from the class Funcionario, so I say a direct is also an employee. Public class Diretor : Funcionario{} Diretor diretor = new Diretor(); But I’m allowed to…
-
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
votes0
answers490
viewsBest way to add product to shopping cart
I have a method that adds product to cart/Session. But I think I’m using a lot of code for this and would like to do it in a better or more simplified way. Any hint? public function…
-
2
votes2
answers99
viewsWhy is it necessary to instantiate a Python class when I can call it directly?
class People: def talk(): print('hello') p1 = People p1.talk() What is the need of instance it if I may call you directly? class People: def talk(): print('hello') People.talk()…
-
2
votes1
answer1359
viewsCalling functions/procedure via buttons using Object-Oriented PHP
I’m starting in PHP O.O and I’m having difficulty calling the functions that are in the class through HTML buttons. In fact, it is not in calling but in setting the values that are in the function.…
-
2
votes1
answer166
viewsWhen will the object be eligible for the Garbagecollector?
From the code snippets below, in which the object created in new Pessoa("João") will be available for the Garbage Collector on the line: //outras instruções ? They are all independent codes. They…
-
2
votes1
answer536
viewsOverloaded Constructors: Instance Initializer
From the perspective of compiler behavior and java class design what would be the justification for using the Instance Initializer block? Considering the following class: class Caneta { public…
-
2
votes1
answer51
viewsHow to obey the Open/Closed principle in this situation?
I have a situation where the solution that I have clearly identified violates the Open/Closed principle and I would like to find a better solution that does not violate that principle. Obviously my…
.net oop modeling software-architecture software-engineeringasked 7 years, 10 months ago SomeDeveloper 18,074 -
2
votes1
answer54
viewsFunction inserting data into the database
I am with this small problem, no matter what I do not right, always keeps giving "invalid query", someone could help me? <?php include('conexao.php'); include('fecha_conexao.php'); function…
-
2
votes2
answers108
viewsIs there a Pattern design that can help with this problem?
I have a problem that seems fairly common to me. The problem, in the specific case, is the following: the user wants to register in the system the services available for sale along with the values.…
oop modeling software-architecture software-engineering dddasked 7 years, 9 months ago SomeDeveloper 18,074 -
2
votes2
answers691
viewsCorrect use of Override and constructor
I was asked to create a current account class that had an attribute representing the fee charged for each transaction of two attributes of the superclass (credit/debit). And have been asked to…
-
2
votes1
answer286
viewsDoes typescript support an implementation equivalent to trait?
I am developing a project using Ionic, and would like to better organize my classes. Below is an example of how I would do with PHP: <?php trait comportamento { public function ficarTriste() { }…
-
2
votes1
answer148
viewsWhat is the importance of the interface in this particular code?
If we will put the interface functions, also inside the class, then create interface? Example: Interface interface Teste { function olaMundo($texto); } Class class Testando implements Teste {…
-
2
votes0
answers38
viewsWhat is the purpose of an empty interface?
I was looking at exceptions to the rule validation engine Respect Validation, and discovered something that caught my attention. This is the interface ExceptionInterface, that apparently, there is…
-
2
votes1
answer62
viewsDemand that one method must be followed by another?
Let’s say I have a class with two methods, and the method x must be executed after the method y otherwise the method x must execute the method y to get the value default. class Classe { private…
-
2
votes1
answer45
viewsHow to use a function of an object as an argument of another function
This is my function that receives an object and uses the attributes of type "Function". FrameWork.prototype.loop = function (objectLoop) { objectLoop.draw(); objectLoop.update();…
-
2
votes2
answers200
viewsIs there any way to implement an interface in a class of a DLL that I can only read?
I am using a DLL that has several classes. I would like to dynamically implement interfaces for these classes, so that I can perform unit tests by making a mock of the same. Is there any way to do…
-
2
votes2
answers519
viewsValidation in an ATM
The user starts by putting a name to the account and the initial balance, here already has a problem, I want it is not possible to enter negative values or broken numbers In the deposit option I…
-
2
votes2
answers1276
viewsUndefined variable in PHP
I am trying to run this PHP code using object orientation and am having difficulties. <?php class Circulo { // declaração de propriedades public $raio = 0; public $area = 0; // declaração de…
-
2
votes0
answers81
viewsWhat is relationship and relational model outside of the database context?
What would be relationship and relational model in the contexts below (removed from here)? Context 1: Double-Dispatch Maniero: I agree and I think [the lack of double-Ispatch support or the view…
-
2
votes2
answers143
viewsHow to program according to good OO design practices?
I did this program, simple and nothing complicated. My problem is that although this is doing exactly what I want, it does not follow correct patterns of object-oriented design. What should I do to,…
-
2
votes1
answer244
viewsPrivate class in C#
I have a class Pessoa.cs private, but I can call her in some other class, for example I created a class called Parametro.cs; I can instantiate the class private Pessoa without the slightest problem.…
-
2
votes1
answer63
viewsAccess data from a class
I’m developing a graph generator to monitor the navigation of a robot. The coordinates the robot passes through are stored in a txt file, with each line having a latitude and a longitude, as…
-
2
votes1
answer174
viewsGood Practice Object Orientation
I have a class called clients. I have 2 methods called verificaCPF() and queryInsert(). Both methods when it makes the instruction it gives a return (is working normal). My question is whether this…
-
2
votes1
answer73
viewsGRASP: Application of the Creator Pattern
Craig Larman (Using UML and Standards, p. 352) proposes the following design problem: Who is responsible for creating a Payment instance? By the GRASP Creator standard, candidates are the Registrar…
-
2
votes3
answers209
viewsPolymorphically manipulating subsclasses
How Superclass Manipulation of Subclasses Works? In this code, the array of one class, prints the values of other classes. zoo java. public class zoo { public static void main(String[] args) { Vaca…
-
2
votes1
answer38
viewsCode before or after super
When screams a method, always comes the super of the parent class, but at the time of coding the right thing to do would be before or after it? In the example below the right would be this:…
-
2
votes1
answer185
viewsHow to access a protected attribute of a package in another package?
I have the animal pack with two attributes: name and rating. package heranca; public class Animal{ protected String nome = "Leão"; protected String tipo= "Mamífero"; } ... And I have another test…
-
2
votes1
answer193
viewsUsing $this when it’s not in the context of the object
I am trying to create a PHP class that connects to the Mysql database and am getting the following error: Fatal error: Using $this when not in Object context Connectdb.class.php class ConnectDB {…
-
2
votes1
answer164
viewsGood practices for class that grows a lot
Supplementing a question I posted here some time ago, about a system for user registration using concepts of the SOLID standard, one of the problems I faced was the question of the User class being…
-
2
votes1
answer385
viewsHow to pass PDO to other objects in MVC OOP application
I’m developing a small framework for learning purposes, and one of the ways I found to pass the PDO object to be used in controllers/models was using the following approach: The constructor method…
-
2
votes1
answer125
viewsAttribute or private field and getter and Setter in Java object-oriented programming
In object-oriented programming in Java, when I create any attribute or private field, without their respective methods getter and setter has to define the attribute as final or need not? For…
-
2
votes1
answer52
viewsHow to make this class usable?
In the code below, I would like to return an instance of the class itself with the data filled through a text file. The lines are stored this way in the file: Yug…
-
2
votes1
answer256
viewsInstantiating an object in the same constructor class is "inelegant"?
It is always seen as a good practice of programming if we create a class for the object, where we have the constructor and make the methods and another class where we instantiate several objects of…
-
2
votes1
answer104
viewsConfiguration file and/or Constants, when to use?
Currently I use constants to store configuration data in my application, but searching saw that it is a "bad practice" by coupling that can generate, I found some questions right here in…
-
2
votes2
answers689
viewsUsing self-free method in Python
I saw in other topics some discussions about passing the self as argument. But it was not very clear to me. Even though my function has no argument to be started I still need to pass the self as a…
-
2
votes2
answers96
viewsPassing object as parameter changes the original object
I’m passing an object as a parameter to another function. In my years of study in college it has always been differentiated the passage by reference and value, in the case of the object it always…
-
2
votes1
answer64
viewsHow to assemble a collection of derived objects, and use specific functions of each?
I want to create a dynamic list that contains all Component derived objects. I’m trying to do it this way: map<string, Componente> tabuleiro_componentes;…
-
2
votes2
answers120
viewsHow to declare a vector with 2 positions?
I have an exercise with the following statement: Write a class whose objects represent students enrolled in a class. Each object in that class must keep the following student data: registration,…
-
2
votes1
answer257
viewsProblems with multiple inheritance and interface use
I am creating a simple bank system (studying), there is a Account class with basic registration information, and a System class that manages all accounts. I intend to create a class ContaDiretor…
-
2
votes2
answers2385
viewsHow to call a method of one class in another class
I had posted earlier but could not edit, I will try to be clearer this time. I am doing (trying)a code for Fonica account. I have class time, connection and contagion. in the account link class I…
-
2
votes1
answer260
viewsCall method with defined vector elements parameter
Good night! I have created a method that calculates the elements of a vector and makes the general mean, but I am not able to call it in the main method. PS: I am a beginner. Thanks for your help!…
-
2
votes2
answers147
viewsObject Array (not objects) in Java - How to use
Hello, I have the following task to do: I have three types of employees (Commissioned, Salaried and Hourly) and I have to add them to a list (ArrayList) to manage them. ArrayList<Commissioned>…
-
2
votes3
answers209
viewsUndefined return when calling function
The console.log(Return) is ok, but only Undefined’s return, could anyone tell me why? let result = []; module.exports = { async atualizar() { await request(url, (err, res, body) => { if (err)…
-
2
votes4
answers428
viewsHow to validate data passed to a constructor?
Is there a way to handle possible errors or validations by instantiating a class using the constructor? For example, this is my constructor: public boolean ContaFisica(int agenciaConta, int…
-
2
votes2
answers177
viewsWhy can’t you access a class attribute in the inherited class?
I have this class: package auladezoitodonove; public class Conta { // atributos private int numeroConta; private String nomeCliente; private int identificador; //Construtores void Conta (){…
-
2
votes1
answer1334
viewsFilter an object array within another object array
I have an array like the one below and would like to filter it by the property that is inside an object inside an array that is inside another object. The idea would be to return all objects whose…