Most voted "classes" questions
In object orientation, a class is a structure that abstracts a set of objects with similar characteristics. A class defines the behavior of its objects through methods and possible states of these objects through attributes. In other words, a class describes the services provided by its objects and what information they can store.
Learn more…715 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?
-
68
votes1
answer19312
views -
51
votes3
answers26529
viewsWhat is the difference between a class and an object?
I was reading a book on object orientation and these two entities are translated differently. What is the difference between the two?
-
42
votes6
answers3282
viewsIs there a Javascript class?
I am studying Javascript and saw some explanations that left me with doubts. Here at Stackoverflow I saw several questions about the possibility of creating an abstract class in Javascript. But my…
-
36
votes6
answers34111
viewsWhat is and what is an abstract class for?
In object orientation, what is the meaning of an abstract class? What is its purpose?
-
32
votes2
answers1436
viewsWhat it means '~' in front of the constructor of a C#class
Working on a project here at the company, I came across some commands that are now being used more (yield, ??, anonymous type) but until I understood, but one who called my attention by not knowing…
-
29
votes1
answer10807
viewsWhen and how to implement Parcelable vs Serializable?
After a long time using the Serializable implementation in my classes on the Java platform (Android), I discovered Parcelable, but I was in doubt regarding the following questions below: 1. When to…
-
28
votes5
answers1775
viewsWhy is it bad practice to have int attributes?
I saw in the answer to that question /questions/17015/qual-o-uso-de-uma-variável-estática-ou-final-em-java/17136#17136, that: It is bad practice to have int attributes, unless they are "constant" or…
-
21
votes2
answers15418
viewsDoesn’t Java have multiple inheritance?
I had seen somewhere now I don’t remember, I think it was in a course on object orientation, which Ruby possesses. But in Java I’ve never seen it. Is that why abstract classes are used? Or is this…
-
21
votes2
answers8871
viewsHow and when to use Interface?
When should I use an interface, in which situations its use is feasible and which is not feasible and how to use it correctly? I developed an example to illustrate a situation, below: using System;…
-
20
votes2
answers1468
views -
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…
-
18
votes2
answers6312
viewsDoubts about the toString() method of the Object class
I’ve been doing some tests with the method toString() class java.lang.Object and found that the obtained result changes with each execution, as the example below: Excerpt from the tested code public…
-
18
votes3
answers437
viewsDatabase should follow the OO standard?
Object Orientation According to the Rules of Pure O, we have: "The Object must manipulate methods and attributes belonging only to it" That is, what does not strictly belong to class should be an…
-
17
votes4
answers2589
viewsIs it possible to create an 'abstract class' in Javascript?
When creating a Javascript class whose attributes and methods are all static (for example, for storing preset settings for a game), I wonder if it is possible to define the class as abstract in a…
-
16
votes3
answers5592
viewsWhere to create a class of its own, and how to instantiate it later?
I have a class of my own (i.e. external to the standard PHP and Laravel libraries) that makes some connections with equipment in my network and also need to create routines for email and SMS…
-
16
votes3
answers675
viewsWhy can’t I declare an attribute using the var keyword?
The keyword var allows me to declare typed variables, and allows variables to be defined implicitly. Example: var i = 10; The compiler will assume that my variable i is of the whole type int.…
-
16
votes3
answers1008
viewsHow is a class organized in memory?
According to this definition of memory: In computing, memory refers to the physical devices used to store programs (sequence of instructions) or data (State information, for example) in a character…
-
15
votes2
answers2572
viewsMain purpose of utility classes
What is the real function of utility classes? Would only reduce maintenance and repetition of code or would go beyond these functions? Would have some way (convention) to use these classes…
-
15
votes5
answers1643
viewsDifference between private and final methods
Studying methods and final classes in Deitel’s book "How to program in Java 6 ed." I came across the following proposition: The declared private methods are implicitly final because it is impossible…
-
15
votes4
answers332
viewsIn relation to object orientation, should queries have a class of their own or can they stay in a specific class?
What I have is this: a user class and a connection class with the bank. I need to insert a user into a database, the query "insert into usuarios values (..)" should be in my user class or in the…
-
15
votes1
answer703
views -
15
votes4
answers8013
viewsSoftware to Create Class Diagram
I would like to know what software is used or if there is an online site to create class diagrams, could someone tell me?
-
15
votes6
answers2755
viewsIs it bad practice to use only static methods in a class?
I was studying further sinking the OOP, learning more advanced concepts such as Polymorphism, Override, Classes and final methods, abstraction, namespace and etc... I learned about static methods,…
-
14
votes2
answers3077
viewsWhy in class statements in Python should we extend Object?
In the Python, when we declare a class, we extend object. class StackExchange(object): def __init__(self): pass I do not know if I am mistaken, but I had the impression that in some versions this is…
-
14
votes6
answers1655
viewsHeritage and Polymorphism
I have the class Funcionario. private String nome; private int idade; public function vender (Funcionario f) { ... } I have the subclasses Gerente and Professor that inherit (extend) from…
-
14
votes5
answers2296
viewsWhat good is a C#?
I saw a class in C# that was stated like this, in a reply I read in Soen: public sealed class Link { // Resto do código } What is the key word for sealed in the above case?…
-
13
votes2
answers477
viewsJava Performance of methods-filled and empty classes
If I create a class whose goal is to group a number of related methods. Suppose a Class Boi{} and it has several methods but no element. For example: public class Ruminante{ public String…
-
13
votes2
answers618
viewsHow to list methods of a class in C#?
Again I have to say this: I come from PHP and am learning C# now. I usually like to list the methods that the class has, because I always did this in PHP, to test or debug. $a = new ArrayObject();…
-
13
votes1
answer924
viewsWhen does it make sense to have only static methods and attributes in a class?
Studying about static methods and attributes in OOP, I came across the following question: because in some codes we have ONLY classes with static attributes and methods? Is there a design pattern…
-
13
votes1
answer1859
viewsReasons to use private class
When I started in the area, in a course of POO (Object Oriented Programming) the teacher explained about access modifiers... I remember that on this very day he said that it would be possible to…
-
12
votes2
answers1221
viewsWhere should I declare an instance variable in Javascript?
I’m having doubts about creating instance variables in a Javascript constructor class/function. I have read in several places that the declaration of an instance variable is made within the class…
-
12
votes4
answers595
viewsHow to create a variable where to access its properties via string?
I’d like to access by string the properties of an object: (EXAMPLE 1) var cor = casa["cor"]; var tamanho = casa["tamanho"]; Instead of accessing like this: (EXAMPLE 2) var cor = casa.cor; var…
-
12
votes2
answers688
viewsClass copy in C#
In C++ programming to copy one class, to another, just do the following: minhaClasse* class_1 = new minhaClasse(); minhaClasse* class_2 = new minhaClasse(); *class_2 = *class_1; // Faz a atribução…
-
11
votes5
answers1562
viewsOptimize function to include classes also looking in sub-directories
I have the following function to include classes when we are trying to use a class that has not yet been defined: /** * Attempt to load undefined class * @param object $class_name object class name…
-
11
votes1
answer5272
viewsWhat is a wrapper class?
What is a wrapper class? How they can be useful? Cite examples of use in php or c#, as well as when to use or not to.…
-
11
votes1
answer603
viewsVariable within a class pointer
I have several header files with GUI management functions that I’ve done to create windows, similar to those libraries like GTK, QT and others, and I’m turning them into library, but I’m having a…
-
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…
-
11
votes2
answers4107
viewsConcept of class, entity and objects
I’m reading about classes in C#, and an excerpt left me a little confused. I know that classes are objects in C#, and can be used in various ways. My doubt is in the following sentence: "A class can…
-
11
votes3
answers663
viewsClass generic property
I have a class with two properties (Name and Value). The estate Name is a string, already the property Value I want to leave the variable type. public class Field<TValue> { public string Name…
-
10
votes2
answers1623
viewsWhat is the real concept and usefulness of POCO classes?
I am studying and developing a new project and the little studying on Windows Phone 7.1, I saw that they suggest/ indicate the use of classes POCO, for database mapping (It seems to me that Windows…
-
10
votes2
answers591
viewsNested class in Java
I need to have nested classes in Java. Why the following implementation doesn’t work? public class A{ private class B{ public B(){ System.out.println("class B"); } } public static void main(String[]…
-
10
votes2
answers2045
viewsAre functions and methods in PHP case-insensitive?
Some time ago, by an accident at the time of a debug I realized that PHP makes no difference between upper and lower case when calling a function. Example: print_r($teste); print_R($teste);…
-
10
votes1
answer112
viewsWhat is the purpose of "&" in the generic type statement?
In that code, the author creates a class as follows: public abstract class GlyphIcon<T extends Enum<T> & GlyphIcons> extends Text { /* ... */ } My question is to understand the…
-
10
votes3
answers271
viewsHow to avoid the use of setters in such cases?
In object orientation it is recommended to avoid the use of setters. The usual justification for this is that the logic that modifies the state of an object must be encapsulated in the object.…
-
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…
-
10
votes2
answers289
viewsWhen to use record or class on C#?
One of the novelties of C# 9 are the record types, I saw that one of the biggest differences between them and the classes are the methods .ToString() and .Equals() who has a different behavior. But…
-
9
votes3
answers407
viewsGenerate setters only in class constructor or generate outside constructor
In Java classes, it is common (At least in college I only see it that way) create private attributes and generate getters and setters for these attributes. But I read that you can do something a…
-
9
votes1
answer383
viewsWhat are classes, how do you use them, and in Javascript?
I started studying programming and Javascript 3 months ago, but so far only in technique. However I realized that it makes it very easy to understand the concept of object orientation. I already…
-
9
votes1
answer21547
viewsHow can one CSS style class inherit from another class?
I have a class circulo with various properties: source and shape, etc and I have another class circulo1 with the property size and color. I have to make several circles of different sizes with the…