Most voted "interface" questions
Used for object orientation concept. DO NOT USE for user interface or hardware component.
Learn more…200 questions
Sort by count of
-
6
votes1
answer290
viewsCalling up graphical interface in java
My doubt is simple, I believe. I need to call this interface CadastroGUI d = new CadastroGUI(); which I already have ready, but I want the fields already appear filled, after all, is a query command…
-
6
votes1
answer2259
viewsUse of the Consumer interface
What is the advantage of using the interface Consummer java-like? Example: I have a class UsuarioConsummer implementing the interface Consummer and calls his way acept, follow suit: public class…
-
6
votes2
answers159
viewsBetter applicability to make an interface functional
Starting from java 8, for an interface to become functional, it needs to have only one right method ? However we have the @Functionface annotation, which explicitly defines that this interface is…
-
6
votes3
answers709
views -
6
votes2
answers614
viewsInterface and inheritance for the Java connection class
Considering the object orientation, would the use of inheritance and interface in this way be correct? But in this way, any request for connection to the database will need a new object. Would have…
-
6
votes2
answers398
viewsWhat are the differences between a type and interface alias in Typescript?
Typescript allows us to create aliases for types. For example: type State = 'inactive' | 'active' | 'banned'; The type allows to also create types for objects, such as: type User = { username:…
-
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
answer930
viewsWhat is the difference between Classes and Interfaces?
What’s the difference between classes and interfaces? I’ve read that apparently the difference in interfaces is because they are 100% public, but I have no idea. Could someone explain the difference…
-
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
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
answer1435
viewsWhat’s the Youtube show for?
If I don’t declare that constant (serialVersionUID) in a class that implements the interface Serializable, I get a Warning. But what is this constant for anyway? Its value interferes with the…
-
5
votes2
answers908
viewsWhat is the real PHP interface utility?
I know what interface is used as a common pattern. But it doesn’t seem useful. Because what good it is to create an interface that only has the name of the methods? I have to encode each of them in…
-
5
votes1
answer1382
viewsWhat is the advantage of using an interface if I always get the same behavior using simple classes in Delphi?
First of all, I want to point out that this issue DOES NOT ADDRESS comparison between abstract classes and interfaces, it aims to find out if there is any advantage in using interfaces to the…
-
4
votes1
answer161
viewsInheritance with interface
How could I solve the following problem. Setting: I have a class B that inherits from class A and implements interface I. Problem: The I interface requires the implementation of the X method which…
-
4
votes2
answers839
viewsHow to check if a class implements a C#interface?
How to check if a class implements an interface? For example, I want to include an if that checks if an object is of the Idisposable type. How to do? I tried something like : MinhaClasse meuObjeto =…
-
4
votes1
answer99
viewsTransform class with static methods into interface
I have a custom class calling for ArrayList, I created to handle objects in a small project of mine, but I’d like to abstract it further, transforming it into an interface. In this way, I could…
-
4
votes1
answer255
viewsWhat is the need for an interface to have abstract methods?
We know that in an interface the methods do not have implementation, only signature, ie only the definition of their methods without the body, we conclude then that all are already methods Abstract,…
-
4
votes2
answers220
viewsStandard implementations in C#interface
I was reading about the new features of C# 8 and came across the Default Interface Implentations, i.e., standard implementations in interfaces. The code below exemplifies public interface…
-
4
votes3
answers290
viewsHow to make compatible objects coming from two different classes, derived from the same interface?
I have an interface (I’ll call it ICliente) which is used as a contract between an application and a DLL. public interface ICliente { int Id {get; set;} string Nome {get; set;} ... } This interface…
-
4
votes1
answer96
viewsNonstatic nested interfaces can be used independent of instance of the enclosing class?
I was reading about JsInterop and I come across an example of code: package com.example; @JsType public class Bar { @JsFunction public interface Foo { int exec(int x); } public static int…
-
4
votes1
answer56
viewsWhat are the differences between Traits (or Typeclasses) and Interfaces?
Studying Rust, I began to make use of the so-called traits that, according to the language book: We can use traits to define shared behavior in an abstract way. The same chapter further quotes the…
-
3
votes1
answer608
viewsWhen you have a reference in Fragment through getActivity() should I use an interface?
My doubt is knowing the best way to work for the organization of methods, I will present 2 implementation options that I am in doubt, whenever I have in Fragment a reference through getActivity() I…
-
3
votes1
answer112
viewsRecommendations for comments on an interface and its contracts
Every day I come across this situation when I will insert comment for an interface and for a class. I wonder if I should use the same interface comments and their contracts, in class and their…
-
3
votes2
answers284
viewsHow to implement classes with private method?
I am rewriting the code of an application seeking the best use of interfaces and I came across a problem: I have a class that needs to have a private method and I want to create an interface for it,…
-
3
votes1
answer75
viewsWhen declaring an interface in the class, who should implement it?
class Gerente extends Funcionario implements Autenticavel { He meant that Gerente implements the interface Autenticavel, or Funcionario which will implement the interface?…
-
3
votes1
answer62
viewsIs it a good idea to use interfaces to specify which magic methods a class will implement?
I’ve seen some code in PHP that, to check if a class has the method __toString, the function is used method_exists. Example: if (method_exists($object, '__toString')) echo $object; On the other…
-
3
votes0
answers1050
viewsDevice gives error and then restarts after trying to uninstall application
I’m having a bug with the application I created, the code is compiling normal and without any error or Warning, and the application is also working on mobile, but when I try to uninstall this…
-
3
votes1
answer838
viewsInterface defining the signature in a generic way of the methods to be implemented
I own three classes: Repositoriosolicitant Repositoriomotorist Repositorioviagem All have the following methods with the exception of Repositorioviagem which does not have "Change". The Object can…
-
3
votes1
answer332
viewsDelphi class with optional full-type field
The question is: how should I build my TPESSOA class so that the _id_city field can be null. Database Create Table PESSOA ( ID INTEGER NOT NULL, NOME VARCHAR(100) NOT NULL, ID_CIDADE INTEGER) No…
-
3
votes1
answer994
viewsDifference between type inheritance and implementation inheritance
My teacher passed a booklet on Object Oriented Data Structure with Java and in the booklet there is an excerpt (without deepening) that says the following: "Interface promotes heritage of type and…
-
3
votes1
answer203
views -
3
votes1
answer454
viewsShould I use abstract class or interface?
I have a class that connects to Windows machines. I’m making it a little more generic so I can repurpose it to other systems. Soon I was able to identify four methods "generic": connect status…
-
3
votes1
answer462
viewsAlternative to multiple inheritance
It is not possible to inherit more than one class in C#, so I come here looking for suggestions for my problem. I am building a small game using Unity. In Unity the game objects (GameObject) inherit…
-
3
votes2
answers106
viewsHow to implement an interface to secure a specific contract?
Need to get an interface to implement a list of a certain type: public class ITrade<T> { public int date { get; set; } public double price { get; set; } public double amount { get; set; }…
-
3
votes2
answers84
viewsUsing interfaces for domain classes
Is it good practice to make use of domain class interfaces? Do I have an advantage in doing so? If so, which one? Example: public interface IAuditoria { long AuditoriaID { get; set; } string…
-
3
votes0
answers113
viewsHow to use interfaces like Dbset’s in the C#Entity Framework
Hello, I’m making a solution where my entire business layer is in a separate project and in this project I created the layer relational structure from interfaces as shown in the example below: //…
-
3
votes1
answer56
viewsHow to make an interface method receive any object (Object type) as parameter?
I’m studying polymorphism now, and I’m not getting it. Given the interface: public interface View { public boolean existe(Object obj); } I have this method, which I would like to be implemented from…
-
3
votes1
answer53
viewsWhy can I assign an instance of a class to a variable whose type is the interface?
Exactly what you mean when I create an object in memory, but I associate it with variable a1 interface-type (AreaCalculavel)? I’m a little confused, see below the example. package exercicio0101;…
-
3
votes1
answer54
viewsImplement only direct methods from an interface
Let’s say I have the interface Vehicle: public interface Vehicle { void moveForward(); void moveBackward(); void moveLeft(); void moveRight(); } And the interface LandVehicle: public interface…
-
3
votes1
answer64
viewsWhat is the access modifier of an explicit implementation?
I created an iterator class that implements the interface IEnumerable<T>, implementing the interface IEnumerable. To make the implementation correctly, it is necessary to explicitly implement…
-
2
votes1
answer172
viewsInterface, interlinking of layers
The use of the interface is only in the interlinking of layers? whenever I want to communicate for example the layer model with the presenter, I’ll need an interface?…
-
2
votes1
answer240
viewsGeneric Locate Method, using ADO.NET and Procedures
I am looking for a solution from a generic repository to a DAL with a generic Find method, so there is no redundancy in my code. Using ADO.NET and Procedures. I found something in this link: What…
-
2
votes1
answer30
viewsGetting an Interface from a Type
I want to see if a Type is implemented by the interface System.IDirectOutput and access their methods, but I don’t know how, I’m trying to: If GetType(IDirectOutput).IsAssignableFrom(Expression)…
-
2
votes1
answer235
viewsImplement Interfaces
I have the abstract class ClasseA and 2 child classes ClasseB and ClasseC, then I have an interface IClasse which is implemented in ClasseA and ClasseB. In the interface I have the method metodo1…
-
2
votes1
answer335
viewsError in multiplication and division (java)
I’m having trouble implementing multiplication and division in my calculator with graphical interface. Regardless of anything I put using any of the operators (/ and *), the output result is 0. Sum…
-
2
votes2
answers459
viewsSend parameters to a C#interface
I created a class called descricaoo that will receive some data parameters and will add in a List of an interface called IInstrucao. But give an error "the descricaoo class is not implemented to an…
-
2
votes3
answers927
viewsHow to declare an attribute in interface?
How can I declare some attributes in an interface? Example, I have the interface called animal, I want her to have some attributes that class mamifero will implement, but the attribute I declare in…
-
2
votes1
answer77
viewsAndroid Studio locked
My android studio IDE doesn’t work right, whenever I try to drag some element to the interface it crashes and just doesn’t respond anymore. The same happens when trying to create Fragments by the…
-
2
votes1
answer1079
viewsInsert background image in Jpanel
I already checked and the path is correct, but when I run nothing appears on the screen: public class MapaInterface extends JPanel implements ActionListener { private Image fundo; public static…
-
2
votes1
answer65
viewsAdding an object to a collection returns "cannot be cast to java.lang.Comparable"
The code is this: public class Catalogo { SortedSet<Produto> lProdutos = new TreeSet(); public void addProduto(int cod, String desc, float preco){ try{ Produto p = new Produto(cod, desc,…