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
-
8
votes2
answers592
viewsBest practices regarding the use of access modifiers
How to restrict other classes from accessing certain members (methods, variables/fields, nested classes/interfaces) one-class? I would like to know the best practices for using the access modifiers…
-
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…
-
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
answers370
viewsPrivate set of property in an interface
I’m modeling a C# interface that has a property. However, I want to ensure that all classes that implement this interface maintain the Setter as private: public interface IBar { string Id { get;…
-
8
votes5
answers993
viewsWhat is the difference between referencing an attribute directly or by get/set
As an example I have a private String atributo, so I can have two ways of referencing the same, this internally in the class: this.atributo And also: this.getAtributo(); It’s correct to say it’s…
-
8
votes1
answer101
viewsPros and cons of securing an interface contract through a subclass
This article presents an interface IList<T> containing the methods Add(T item) and Count(). The contract of that interface expects that when an item is added, the method Count() reflects the…
-
8
votes1
answer148
viewsAccess null pointer is not generating error
Testing the code below, I noticed a strange behavior. It’s working when it shouldn’t. The correct in my view was to give a segmentation failure and abort, but it seems that the compiler is doing…
-
8
votes2
answers112
viewsAbstract methods do not require implementation
I am doing a job and implemented an abstract method, the case makes a class inherit this, but the compiler does not accuse error for the lack of implementation of the methods. I’m doing it wrong?…
-
8
votes4
answers635
viewsWhy can objects other than the same class access private fields from each other?
Today while I was taking a course in Udacity (Intro to Java Programming) I thought about this in the exercise Update the class Person (lesson 3 29/45). In object-oriented modeling we have the…
-
8
votes2
answers291
viewsCan I use class and struct at the same time?
I have a variable "Address", however, it is composed by "Street", "Number" etc. The way I did below is the best to be done? With class and struct at the same time? Or is there something better and…
-
8
votes1
answer231
viewsHow to use the 9th rule of Object Calisthenics in PHP?
Object Calisthenics making a translation into Portuguese means "programming exercises", and consists of 9 rules created by Jeff Bay in his book The Thoughtworks Anthology. The Object Calisthenics is…
-
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
votes2
answers1163
viewsWhen to use instance variables vs parameters?
Assuming that a class A use a class B (directly or through an interface C to uncouple A of C). Making it clear that A and B are independent parties, i and.., the relationship between the two classes…
-
7
votes2
answers358
viewsReference in Flyweight design pattern
There’s something about Desing Pattern Flyweight that’s really getting me confused. Briefly, the pattern says that to save memory in a situation where you use several similar objects, you use a…
-
7
votes2
answers360
viewsTheoretical doubt - Interface, unique responsibility
Presentation: I created a photo.Cs class that should be responsible for: Calculate the angle of view of the lens; Receive lens zoom (in mm) Receive the cut factor (value multiplied by the lens zoom…
-
7
votes1
answer700
viewsWhat’s it for, and when to use Friend?
Code example: Friend Const Public Frind
-
7
votes1
answer329
viewsPolymorphism in Java
Example: // Super classe: Carro abstract public class Carro { String nome; public void andar(){ // anda } } // Sub classe: Fusca public class Fusca extends Carro { public void andar(){…
-
7
votes2
answers104
viewsHow to resolve duplicate PHP object?
I have 2 objects with different values, but when I save it saved as a single object. Example of how I’m using: class Objeto { private $Nome; public function setNome($Nome){ $this->Nome = $Nome; }…
-
7
votes3
answers1335
viewsHow to use an object to add to an attribute?
When I do the code below you get this error: Object of class Client could not be converted to string in ... animal.class.php In this part does not allow me to pass an object to be used in the…
-
7
votes2
answers129
viewsBoxing is copying the data
Boxing is to transform value type in Reference type, right? But when we copy a Ference type into another Reference type, it just copies the address and not the value. But when I convert int for…
-
7
votes3
answers1072
viewsWhat is and what is the function of . (dot) in POO?
A long time ago a teacher defined and explained the function of . in POO (Java class). With time I ended up forgetting, but I found it quite interesting, often we think is just a "point", however,…
-
7
votes2
answers329
viewsHow to transform attributes into properties?
In C#, I can avoid using getter and setter, transforming the attributes into properties, as below: public class Pessoa { public int pes_idade { get; set; } public string pes_nome { get; set; } } You…
-
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
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
votes4
answers1466
viewsHow best to pass values to attributes
I am studying object-oriented programming. I am very fascinated as this new world. But now a doubt has arisen. I believe you can help me. I’m doing a Person class, which has the attributes name, age…
-
7
votes1
answer79
viewsWhy can’t a Trait implement an interface?
Why a Trait cannot implement an interface in PHP?
-
7
votes2
answers820
viewsWhat is type and state inheritance?
Recently in a Java simulation, I came across a question related to inheritance classification, which I had never seen before. Taking the opportunity, I will separate into topics, so that the answer…
-
7
votes2
answers65
viewsWhat to do when a model has N responsibilities
My system exists a class that is currently a common class for several situations, below some of the other models to exemplify public class Servico { public int Id {get;set;} public string Nome…
-
7
votes1
answer249
viewsEverything I can do in POO I can do in PE?
Can I do everything or change anything? I have limits in structured programming where in POO I don’t have?
-
7
votes1
answer3710
viewsWhy use static python methods
I’m studying about the subject of the title and I can’t get the idea with the explanation on video and the Stk I found, so when and why we use static method @staticmethod in python, one has some…
-
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
answers454
viewsWhy was the parameterized class attribute <T> not instantiated?
I have this class that implements the IDAO interface package DAO; import java.util.ArrayList; public class BdApp<T> implements IDAO<T> { ArrayList<T> lst = new…
-
7
votes2
answers327
views -
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
votes2
answers2693
viewsWhat is a domain class?
What is a domain class? Why "domain"? Are there methods that it should not have (which is not its function to have determined type of method)? It admits what kind of methods?
-
7
votes1
answer201
viewsMeaning of "code acting on data" and "data controlling access to code"
This is a purely theoretical question about programming. I would like to know from an example simple (response with complement of figures, drawings, etc.), the meaning of two sentences for two types…
oop terminology software-engineering encoding-style structured-programmingasked 6 years, 2 months ago neves 5,644 -
7
votes1
answer4432
viewsHow to create Javascript interface?
I believe most of you know the concept of Interface, fairly widespread in POO, but in Javascript in all projects I worked until today I have not seen use of this concept. I did some research on, but…
-
7
votes2
answers299
viewsCompared to Datetime class, is the date function more performative?
It is very common to read some tutorials or articles saying that programming Object Oriented can cost more (I speak in relation to memory). Since I started programming, there’s that little itch in…
-
7
votes1
answer475
viewsWhat are application and domain services in Onion Architecture?
In Onion Architecture there is the core (application that includes domain objects, Domain Services and Application Services): I am in doubt about what the last two are (Domain services and…
-
7
votes1
answer304
viewsIs it correct, following object orientation, to use pointers to C++ functions?
I am creating classes that represent items in a menu, each item performs an action and I am assigning the action by a function pointer to each instantiated menu item, is this valid by following POO?…
-
7
votes2
answers658
viewsWhat does a class diagram contain?
The title is a kind of stupid question, because the name of the diagram already answers. But yesterday this question came to mind when a professor of Analysis and Software Projects asked the whole…
-
7
votes1
answer88
viewsWhat is the advantage of PHP objects being passed by default references?
From PHP 5 an object variable no longer contains the object itself as a value. It contains an object identifier that allows the object’s "accessors" to find the real object. I recently went through…
-
7
votes3
answers7194
viewsWhat is a method " __contruct()"?
I am starting studies on POO, and came across the following method: <?php class ShopProduct { public $title = "default product"; public $producerMainName = "main name"; public $producerFirstName…
-
7
votes1
answer140
viewsIs the purpose of the inheritance reuse?
Many say that the goal of object-oriented inheritance is to promote code reuse, but I believe this is a mistake. I remember (or think) reading that the goal is NOT reuse but I don’t remember now…
-
7
votes2
answers229
viewsIf I can do everything with structural programming, why did you create object-oriented?
In the question about - Everything I can do in POO I can do in PE? - the answer accepted and better voted says: Yes, any programming language can do anything. Now, each paradigm has its own way of…
-
7
votes2
answers412
viewsWhat is the Demetrius Law about?
In a contest, I found the following question: In Object-Oriented Programming, the law of Demetrius (Law of Demeter) says that a method m of an O object should not invoke methods of following object…
-
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…
-
7
votes3
answers171
viewsIs APOO useful today?
I went there on Engineering.SE software and asked what has APOO (Object-Oriented Analysis and Project) methodology prominent today (here in Brazil there is not much, but there in the USA, will…
oop software-engineering uml software-project methodologyasked 6 years, 5 months ago Piovezan 15,850 -
7
votes0
answers166
viewsHow to learn object orientation correctly?
A lot of the "OO" code you see around is procedural. I have already committed and continue to commit several "sins" per day by programming OO. The paradigm is not easy to learn and it takes time,…
oop software-engineering software-project programming-principlesasked 6 years, 1 month ago Piovezan 15,850 -
7
votes2
answers707
viewsAre class methods recreated for each instance in Python?
By what I observed when generating an instance of a class all class methods are recreated in a different memory position as in the excerpt below: class Foo(): def __init__ (self): self.x = 10 def…