Summary, interface - when to use what?

I am relatively new to Java - especially when it comes to interfaces and abstract classes (I do know how to use them), however in this case i am a bit confused how i should setup my architecture. First of all, i'd like to say that this is just a proj

Java Enum Methods - Switch or Replace for Each Object

Let's consider an enum. What's the difference between creating one method with "switch(this)" for each object and creating one abstract method and overriding it for each object in enum?There isn't necessarily a difference while you don't change

generic abstract class constructor

I'm trying to call a constructor for a generic abstract class within a method of said class. The code below shows this: public abstract class Node<T> { public Collection <Node<T>> pars; public Collection<Node<T>> interactors;

C #: Force the builder's signature using the abstract class?

I've been searching for a while on this because I'm naturally forgetful and I thought it would be nice to build something (an abstract class, interface, etc.?) that would force me to implement certain bits of code in a class I was writing. In particu

Declare enum without specifying values, something like abstract

I have an abstract class (or an interface). In this class I want to define an enum, in order to force classes that extend this abstract class (or implement this interface) to declare an enum with the same name. abstract class Operator { public abstra

create an object using abstract classes

I am trying to understand better oop ,but I don't understand how to use abstract classes. I have a car class, and a car can be mercedes , audi and volvo. Mercedes cars can have 5 passengers ,can open door and block windows; audi car can have 6 passen

How to make an abstract variable feature in Java

I am trying to create a custom class that extends another class (JFrame) but forces the assignment of a certain variable upon implementation (I want each JFrame in my application to have a "screen ID"). Java, however, does not have abstract vari

Access to type-specific methods & ldquo; class, in a collection

Situation: I have an abstract class with several methods: I have a few sub classes that extend the class above I have a collection <MyAbstractClass> collection filled with new objects of the sub classes in my main class I have a unique method of one

Java abstract method signature

I am quite confused about abstract method signitures that Java classes implement. For example, consider: interface Programmer { Object program(); } class Linus implements Programmer { public String program() { return "goto end;"; } } public clas

The best way to declare an interface in C ++ 11

As we all know, some languages have the notion of interfaces. This is Java: public interface Testable { void test(); } How can I achieve this in C++ (or C++11) in most compact way and with little code noise? I'd appreciate a solution that wouldn't ne

Runtime flow of the Java Graphical Paint Method

I came across this code. I thought I alleviate this confusion before I run into any hiccups along the way in programming. I am having trouble understanding whether the paint or the actionPerformed method gets executed first in Board class. I hope my

abstract classboards and oop design - Java

I have a class component abstract class Component{ private componentType m_type; public Component(componentType type) { m_type = type; } } and 2 subclasses class AmplifierComponent extends Component{ public AmplifierComponent() { super(componentType.

Generic Java subclass arguments

I'm sorry if this question has been asked before, but I don't really know what to search for. Anyway, I'm making a math package, and many of the classes extend Function: package CustomMath; @SuppressWarnings("rawtypes") public abstract class Fun

Error 1 The 'abstract' modifier is not valid for this item

I'm trying to build my C# project, I get the error: The modifier 'abstract' is not valid for this item In the following Interface: namespace program.Drawing.Fields { using System; using System.Collections.Generic; using System.Runtime.CompilerService

Using the Lambda expression causes the class type to change

Ok this one is puzzling me. I have an abstract base class named Testbase and it has an abstract function called RunTest. In a folder I have a collection of classes that inherit this abstract class. In a test controller I call the following code to cr

How to generate a program model by generating an abstract class

i have the following problem. The 1st step is to implement a program, which follows a specific protocol on startup. Therefore, functions as onInit, onConfigRequest, etc. will be necessary. (These are triggered e.g. by incoming message on a TCP Port)

Abstract C ++ class template

I have the following code: template <typename T> class ListBase { protected: int _size; public: ListBase() {_size=0;} virtual ~ListBase() {} bool isEmpty() {return (_size ==0);} int getSize() {return _size;} virtual bool insert(int index, const T &a

How can I inherit an inner class using an abstract base class?

I'm trying to create a test class which organizes its test methods using inner classes. I would like for this class to be abstract with the ability to set a static property so this property can be injected. Here's an example of what I'm talking about

Java - abstract class, equal to (), and two subclasses

I have an abstract class named Xpto and two subclasses that extend it named Person and Car. I have also a class named Test with main() and a method foo() that verifies if two persons or cars (or any object of a class that extends Xpto) are equals. Th

How to initialize a Graphics object in Java?

this is the code: import java.awt.*; import java.applet.*; public class anim1 extends Applet{ public void paint (Graphics g) { g.drawString("",400,300); } public static void main(String ad[]) { anim1 a=new anim1(); Graphics g1; a.paint(g1); } }

Abstract basic classes and fields of application

I apologize now if my upcoming explanation doesn't make enough sense; I'm reknown for it, though I try to do otherwise. I'm writing a service that makes use of user-defined plugins. I'm trying to isolate them -- keeping their assemblies out of the se