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
-
6
votes2
answers221
viewsUse of methods in php object orientation
Hello, I have the following question: In this example: class produtos { public categorias = []; } categories is a vector, as you can see. Its structure is as follows:: $categorias["tvs"][0] = "aqui…
-
6
votes1
answer2127
viewsHow to clone objects in Python?
In some languages, besides being able to instantiate a class to construct a given object, we can also clone an existing instance, if we want an object with the same characteristics of the current…
-
6
votes1
answer3084
viewsCall a method that calls another method of the same class?
Example have the class Metodo: public class Metodo { private String string; public String mostrar(String nome, String sobrenome){ this.string = "Nome: " + nome + "Sobrenome: " + sobrenome; return…
-
6
votes4
answers640
viewsJava abstract class exercise doubt
I would like to ask for your help again in this exercise. This time using the abstract class. Create an abstract class FuncionarioAbstract with the attribute String name and abstract method: public…
-
6
votes1
answer247
viewsIs my code object-oriented?
I have a code and would like to know if it is an object-oriented code. It follows the structure. I work with 3 files. first flame save.php, follows the code: include_once('dao.php');…
-
6
votes1
answer90
viewsHow do I know my function is breaking SOLID POO?
I left a function below that will be the subject of the question, basically I would like to know if this function breaks any principle of SOLID/Clean Code by itself ? This doubt arose because…
-
6
votes2
answers140
viewsHow do I access getters and sub-class setters?
In this application we have the class Automóvel: public class Automovel { private String marca; private String matricula; private String anoConstrucao; private Motor motor; private int preco = 0;…
-
5
votes3
answers208
viewsComposition: use @class or #import?
I recently had a problem with Unknow type name 'Class', 'cause I was doing import in the header of 2 classes. I discovered that this is a classic error of headers importing headers. I was directed…
-
5
votes2
answers756
viewsHow to use arrays in Java?
It’s a very beginner question (I’m new to Java, I came from C++). I have to do a program that takes 4 grades from 10 students, but when I go to work with the "pointers" (arrays), my program returns…
-
5
votes1
answer2491
viewsDifferences in the dynamic creation of an object
When I create an object dynamically, for example a form, I do so: Formulario := TFormulario.Create(nil); try Formulario.ShowModal; finally Formulario.Free; end; What’s the difference in creating an…
-
5
votes1
answer384
viewsProblem with Java timer
Explanation: I have a component JTextField that would be a regressive counter, but when I use the ActionListener in this way: public static ActionListener alredBGolem = new ActionListener() { public…
-
5
votes3
answers157
viewsWhy does this violate Strict Standards?
take into account the following definitions of classes: class SuperDate {} class SubDate extends SuperDate {} class Foo { public function setDate(SubDate $date) {} } class Bar extends Foo { public…
-
5
votes1
answer3020
viewsWhat is the best way to create methods accessible to any Ctivity?
Hello. When I need to create a method for an Activity I simply write it in my Activity code. For example: package com.pcriot.maxsoft.testapplication; import android.os.Bundle; import…
-
5
votes1
answer365
viewsWhat does "introspection at runtime" mean?
Looking for information about a graphic Toolkit in Lua, I found an explanation about lgi (GTK) that presented a great advantage: "...because it was written in C and has the ability to introspect at…
-
5
votes0
answers75
viewsWhy should we prefer composition over inheritance?
Since the popularization of object orientation in the 90’s I hear that composition should be preferred before creating hierarchy of types. But perhaps the most important concept of object…
oop inheritance software-engineering composition liskov-principleasked 10 years, 7 months ago Maniero 444,682 -
5
votes2
answers310
viewsStatic Methods in Factory Method
I’m creating a class using Factory Method and I came up with the following question:. The use of static methods in Factories? In many examples I found we have to create an instance of the class…
-
5
votes2
answers1174
viewsInstantiating an Object with a different reference
I’m learning polymorphism in Java, but I’m having some doubts. public class Animal { int numPatas; public void fazerBarulho() { // Código do Método } public void comportamento() { // Código do…
-
5
votes1
answer120
viewsIs it possible to call the Internal (no visibility operator) method from a class inherited from another package?
Problem I’m trying to create some extra behaviors in some native Android components. For that I am creating a class above the Android component and rewriting some situations I intend to have a…
-
5
votes1
answer2687
viewsWhat is simple association in object orientation?
When I asked here on composition and aggregation I was thinking that any association between two objects fell into these categories (not counting inheritance). But then in the answer I saw that…
oopasked 10 years, 6 months ago SomeDeveloper 18,074 -
5
votes3
answers3244
viewsCalling a method from a Javascript class (OOP)
Good staff would like to know if it is possible to access a method of a class(javascript) without knowing if the variable by instance it. function SDK(dynamicUrl) { var data = 'DATA'; var atual =…
-
5
votes2
answers2617
viewsHow to list objects of a deteminated class?
For example, let’s say I have a class TConfiguracao. Here constructors and destructors attributes and in some cultures I create several variables of the type Tconfiguracao conf1 :TConfiguracao;…
-
5
votes2
answers117
viewsInheritance or Addiction?
Well, my question is this. I’m refactoring a system where I have an integration with a REST API, there’s a class called Marketplace (That queries the API) that I currently extend from the class Curl…
-
5
votes1
answer608
viewsDifferentiate interface "instance" class instance
Got some way of differentiating v1 of v2 in the code below, by reflection or other method? var v1 = new MinhaClasse(); IMinhaClasse v2 = new MinhaClasse(); I want to run a method only if a variável…
-
5
votes1
answer781
viewsHow to save data to a global array
I am studying PHP, and so far I have developed a small system that "mounts" the site views and etc. But I came across an extremely annoying problem that I can’t solve. I need a function to show the…
-
5
votes2
answers180
viewsUse Static Closures or Closures in PHP?
As of PHP 5.4, the Closures (Or funções anônimas), when declared within the context of a class method (other than static methods), automatically inherit to "within" the $this as a reference to the…
-
5
votes3
answers2556
viewsHow to know how many objects were instantiated?
In a Java application, how do I know how many objects in a class were instantiated? This doubt came to me by reading the article mentioned in the link below. It follows the excerpt that led me to…
-
5
votes3
answers698
viewsIn OOP, what are the differences between Afferent Coupling and Efferent Coupling?
With regard to the concept of acoplamento in Programação Orientada a Objetos, what are the differences between Acoplamento Aferente and Acoplamento Eferente? If possible, to better elucidate the…
-
5
votes2
answers2743
viewsHow do I set a private property in Python? And is there a protected property?
I come from PHP. In it, when we want to define a property of a class as private we add the keyword private in his statement. Example: class StackOverflow extends StackExchange { private $language =…
-
5
votes1
answer432
viewsInsert php with object as parameter
I’d like to understand how I can do an insert function in php that uses an object as a parameter. Example: class Aluno{ private $nome; private $curso; } getters e setters... public function…
-
5
votes4
answers334
viewsAdvantages of Inner Class
Since I started programming for Android (I believe due to Google examples), I have a habit of creating internal classes for functionalities related to Activity. Example: If the Activity connect to…
-
5
votes1
answer761
viewsUse PDO Prepared statements in function
I’ve been reading about prevention sql injections and saw to use Prepared statements can help with that. I have the following function in a crud class I developed: public function inserir($tabela,…
-
5
votes2
answers2039
viewsWhat is a hook method?
I am studying some design standards and came across this method, however, its concept was not clear to me. What the method does and how it relates to the Template Method? I’d like an example in…
-
5
votes2
answers1863
viewsWhat is the purpose of the default when used in the signature of a method?
Within the interface List<E> of Java there is the method replaceAll() the purpose of which is to replace all occurrences of a specified value of a list. However, in his signature he uses the…
-
5
votes1
answer95
viewsDo static methods equate to functions?
In OOP we have static methods (do not depend on any instance variable). Citing examples: class Somar { public static function soma($a,$b){ return $a+$b; } } echo Somar::soma(20,30); The equivalent…
-
5
votes1
answer550
viewsCan one override in builders?
Is it possible to override in builders? For example: @Override public class main (String arg[]){}
-
5
votes2
answers711
viewsWhere to put the business rule at the angle?
I love programming web and mobile apps with Angularjs. But I’m tired of spreading my business rules by controller and factorys. I miss being able to create my objects with their respective…
-
5
votes2
answers564
viewsIs there a difference in using constants or variables in Classes?
There is a difference in using constants or variables in Classes?
-
5
votes3
answers185
viewsIfs and Object Orientation - C#
I have a question about how to replace IF with polymorphism. I will give the following example: Let’s say I have the classes ExecucaoIndividual and ExecucaoGeral. For this I created an interface to…
-
5
votes1
answer112
viewsHow and when to use "Shadows" and "Overrides"?
How and when to use Shadows and Overrides? What are the usage recommendations for each and in what context to use them?…
-
5
votes1
answer558
viewsWhat is the difference between a Mediator Class (Interposer Class) and a Helper Class (Helper Class) in Delphi?
I’ve always worked more with interposer classes. I know it’s best to create components, but sometimes it’s faster to make a point adjustment using an interposer. New versions of Delphi have the…
-
5
votes1
answer4635
viewsHow to resolve a "Catchable fatal error" error
I’m doing some object orientation exercises in PHP and when changing the database data, I come across the following error Catchable fatal error: Object of class mysqli_result could not be converted…
-
5
votes2
answers185
viewsHow to know which methods and properties I put in a class?
I’m going to do my first commercial system using C#. The system will be used to manage the guests and rooms of a small hotel, for now that’s all he asked for. Obviously I am happy with that, while…
-
5
votes2
answers446
viewsIn the POO when to use Re-turn?
I have a question related to POO, when should I use the return in a method?! Since when I pass an object to the method and modifications are made to it, I do not need to Return, example below:…
-
5
votes3
answers66
viewsClass attribute does not generate error when commented
I had a question that I could not solve. Follow the codes of 3 files Php user. class Usuario{ //protected $nome; public function getNome() { return $this->nome; } public function setNome($nome){…
-
5
votes1
answer109
viewsHave the functional features of Java 8 made any Pattern design obsolete?
It is said that functional programming makes certain design patterns (thinking of the Gof) unnecessary. There’s even a presentation showing it somewhere (I’m not looking now because I’m on cell…
-
5
votes2
answers351
viewsIs it possible to use $this with static methods?
Before questions or criticisms arise about not being able to do this simply because the methods static not having access to variables and public methods, private and protected, because they are…
-
5
votes5
answers156
viewsType induction for any type of object
I am wanting to make a method of a certain class accept an object as a parameter. However, this object could be of any type. Example: class classeExemplo { public function meuMetodo(Object $objeto)…
-
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, 8 months ago user3671786 55 -
5
votes3
answers119
viewsWhy declare property twice in one class?
When declaring a property in one class, they usually declare twice, one public and the other private. What is the purpose? private int _years; public int Years { get { return _years; } }…
-
5
votes2
answers146
viewsDeclaration of `var as object field
How could I declare a variable var public so that it could take the return of the data. How would the statement of these variables without completion: var tbuscar = ?; var retorno = ?; public bool…