FAQ Database Discussion Community


Implementing Iterator for abstractCollection

java,generics,iterator,override,abstract
Hi I want to implement the iterator for a class that extends abstract Collection. class Name<E extends Comparable<E>> extends AbstractCollection<CompRational> implements Iterable<E>{ ... public Iterator<E> iterator(){ return new NameIterator<E>(this); } ... } and the Iterator should look like this class NameIterator<E extends Comparable<E>> implements Iterator<E>{ private Name<E> tree; private int...

Extending Generic Abstract Class: Correct Bounding

java,generics,abstract
public class GenericTest { public static void main(String[] args) { Manager<SlotA> mA = new Manager<SlotA>(); } } class Manager<SlotClass extends Slot> { } abstract class Slot { public Slot(Manager<? extends Slot> m) { } } class SlotA extends Slot { public SlotA(Manager<SlotB> m) { //a constructor with Manager<SlotA> is not...

How to implement pure virtual functions with different parameter structures

c++,polymorphism,virtual,abstract,pure-virtual
I'm building a class with pure virtual functions called Database. The idea is to have a class that handles all the database interfaces (ie: open and close) and can be used on my business layers. The Database class will be implemented in several 'flavours' for different databases, like mySqlDatabase and...

Java: Abstract classes methods and interface

java,interface,abstract
The program below calculates the total of the areas of any number of shapes instantiated. The problem is that I don't know how to output the draw() method of the interface. Here is the main class: public class MyClass1{ public static void main(String[] args) { Shape[] shapes= new Shape[3]; shapes[0]=...

Reuse conditional statements in sub-classes.

java,abstract,dry,abstract-methods
I have below classes: public abstract class Parent { public abstract boolean checkName(String str); } public class Child1 extends Parent { public static final String NAME = "CHILD1"; @Override public boolean checkName(String str) { //check input validity: if (!NAME.equals(str)) { throw new IllegalArgumentException("some thing"); } //... } } public class...

Android abstract class error for method

android,class,manifest,abstract
So i followed a simple tutorial line by line but am getting the error message: Class stepcounter must either be declared abstract or implement abstract method onAccuracyChanged(sensor, int) in sensorevent listener. Edit:// i changed the public class to public abstract class but i attempted to add it to the manifest...

boost serialize polymorphic class

c++,serialization,boost,polymorphism,abstract
With the following example I attempting to learn a few new to me concepts. abstraction polymorphic classes factory programming. boost serialization The nuances of how pointers behave are still something I am working to figure out. Here is a small program that I have written to show you the issue...

Identify method's signature using inherited classes in Java's abstract methods

java,oop,inheritance,abstract
I know this is a very simple question, but I have been working in Python for quite a long time and now that I must go back to Java, I seem to have problems changing the chip and wrapping my head around Java's basic polymorphism. Is it possible to overwrite...

Actions is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener

java,swing,class,abstract
I was copying some code from a tutorial book and I have a problem I cannot resolve. Here is the code: import javax.swing.*; import java.awt.event.*; class Actions extends JFrame implements ActionListener { JPanel panel = new JPanel(); public static void main( String[] args ) { Actions gui = new Actions();...

Dynamic return type of implementation declared in abstract method

java,generics,abstract
I am looking for a way to have, in an abstract method, the return type to be the one of the implementation calling the method. In other terms, I would like to write something like that: public class GenericClass { public <T extends GenericClass> T returnMyself() { return (T)this; //...

Java - Force Inheritance of 1 of N Overridden Abstract Methods

java,inheritance,override,abstract
Using Java 6, I have a situation where I want to force a child class to implement 1 of N overridden methods. Let me explain with an example: public abstract class TestClass { public abstract String isValidInput(ObjectOne objectOne); public abstract String isValidInput(ObjectOne objectOne, ObjectTwo objectTwo); public abstract String isValidInput(ObjectOne objectOne,...

Abstract inner class within non-abstract outer class

java,abstract-class,abstract
I have a super-class A with an abstract inner-class Inner, with another class B that extends A. Why doesn't A force B to implement the abstract inner-class? I've already looked here, but it only specifies abstract methods in non-abstracts classes. Does the same principle apply here? public class A {...

Cannot instantiate abstract class: Why is the template parameter (reference) causing this?

c++,templates,abstract
I am having trouble with some code. 'Bar' : cannot instantiate abstract class I have (finally) been able to recreate the error in a small amount of code. struct SomeStruct { // ****** }; template <typename TIN, typename TOUT, typename TINDEX> struct IFoo { public: virtual void add(const TIN item)...

C#: Define methods implementation in base class and properties in derived classes

c#,inheritance,abstract
I am making a game in which I have many kinds of soldiers, each kind with their own attributes (speed, attackPower...). Obviously, all of them can Walk, Attack... so I thought that creating an abstract class Soldier with those methods, and subclasses with each unit attributes would be the appropiate....

Issue with type safety within abstract class

java,generics,static,abstract
I've recently started working on a new project in Java which will have a local database. As part of the design, I have created an AbstractEntity class - this is intended as an object representation of a row (or potential row) on the database. I've run into a few issues...

Type error when when trying to override a generic function in a concrete implementation of an abstract class

scala,generics,abstract
The error can be reproduced in the console with the following code. case class SomeClass(name: String) abstract class Factory() { protected def create[U](name: String) : U } class SomeFactory extends Factory() { override def create[SomeClass](name: String) = SomeClass(name) } <console>:11: error: type mismatch; found : SomeClass(in object $iw) required: SomeClass(in...

No error while instantiating abstract class, even though abstract method is not implemented

python-3.x,abstract-class,abstract,abc
I was trying out the below python code: from abc import ABCMeta,abstractmethod class Bar: __metaclass__ = ABCMeta @abstractmethod def foo(self): pass class Bar2(Bar): def foo2(self): print("Foo2") b=Bar() b2=Bar2() I thought having @abstractmethod will ensure that my parent class will be abstract and the child class would also be be abstract...

C++ accessing member of subclass of abstract class pointer vector

c++,class,vector,polymorphism,abstract
Error over here: Rocket.cpp:31:16: error: no member named 'getThrust' in 'RocketPart' rocket[0]->getThrust(); When I want to access getThrust() from class Engine over the vector<RocketPart*> rocket with rocket[i]->getThrust(), I get the error message from the top of my question. What am I doing wrong? Is it possible to access it over...

Fill a hashmap in superclass from subclass constructor in Java

java,javafx,subclass,abstract,superclass
I have an abstract superclass that is set up like this in JavaFX: abstract class View { protected static HashMap<String, View> viewMap; View(){ viewMap = new HashMap<String, View>(); } public static void addMap(String key, View value){ viewMap.put(key, value); } This super class includes the method: public static VBox goToView (final...

Get and use class from calling object [closed]

java,abstract
Let us say that we have in abstract class the following method. public Object Foo() { [X] someObject; /* some operations*/ return someObject; } What I want is that to get and use the class of the calling object from a class extended of the method over. The [X] represent...

Limiting visibility of abstract base classes in C#

java,c#,interface,abstract,privacy
I feel like this question may be off topic as subjective, but I'm curious. In java I'm used to using package private and public to hide the implementation of types from other packages. I usually have an interface such as: public interface IMyClass { ... } Any common functionality of...

django form: pass parameter to is_valid

django,forms,validation,parameter-passing,abstract
I have an abstract form and 2 forms using it. In the is_valid method of the abstract form, I check for a condition and that condition depends on the form calling the method. The line is: if eval(self.cleaned_data.get("validated_modif")): According to the form, it should be replaced by one of the...

Java Override Abstract Interface Method

java,interface,override,abstract,implements
I have a BankAccount.java that implements NamedAccount.java which is an abstract interface, but it keeps giving me an error that since BankAccount.java is not abstract it can't override it. How do I fix this problem? I tried adding @Override in both situations but it does not work! BankAccount.java: public class...

Abstract Classes - Super Constructor (Java)

java,class,abstract
I have a really simple question: Let's say I have an abstract class which represents a person in a bar. public class Person { protected String firstName; protected String lastName; public Person(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } } And I also have 2 classes...

Using array the objects the class abstract

java,arrays,class,methods,abstract
i have 1 problem, I can not open my method , I do not well downcast. i have 3 class, and 1 is abstract. public abstract class Canideos { public abstract String ladrar(); } public class Gato extends Canideos{ @Override public String ladrar() { String ladrar="miau miau"; return ladrar; }...

Set Moq CallBase to be true by default

testing,moq,abstract
See here for why I want to have CallBase set on my Mock objects: How to use moq to test a concrete method in an abstract class? It would be nice not to have to set this on every one of my mock objects. Is there any way to set...

AngularJS reusable factory

javascript,angularjs,factory,abstract
I feel like this is probably a dumb question but I'm having trouble visualizing how to make this work. I have a factory used to share data between controllers, like this: app.factory('DataShare', function(){ //Share Data between controllers via the sharedItem object and the get/set functions var sharedItem = {}; function...

How does this Java code instantiate an abstract class?

java,class,syntax,instantiation,abstract
I am making changes to a Java class of ours, and I noticed the following line of code: OurClass<OurInterface1> ourClass = new OurClass<OurInterface1>() {}; What I find strange about that line is that OurClass is an abstract class - here's the definition of OurClass: public abstract class OurClass<T extends OurInterface1>...

Abstract classes in Java

java,class,graph,nodes,abstract
So, I have an object-oriented assignment to do. Small part of it is to make a graph, made out of nodes, which can be either a type category or type product. The category has only a name ([a-zA-Z0-9]+) as parameters. The product hast a name ([a-zA-Z0-9]+) and an id (>=0)....

Abstract class and methods, Why?

java,class,methods,override,abstract
Hope anyone can help, i am learning Java and as comparable to anyone else in this forum i guess i am a newbie to programming as well. I have come across a chapter on abstract class and methods but don't really fully understand what they are used for and why,...

Why can't I add extra argument validation in the subclass constructor?

java,validation,constructor,abstract,superclass
I have two classes. The superclass: public abstract class Question(){ public Question(String question, String answer, String... alts){... } And the subclass: public class StringOptionsQuestion extends Question { public StringOptionsQuestion(String question, String answer, String... alts){ if (alts.length == 0){throw new IllegalArgumentException();} //The compiler doesn't like this line. super(question, answer, alts); }}...

Java: OOP advice and suggestion to advance a small app

java,oop,arraylist,collections,abstract
So this project is a little outside of my comfort zone. I would describe my current stage of development as being one in which, “I know about things like: collection, design patters, and in general what makes for good OOP. But these things are sort of at my current limits....

How to instantiate a new object from an abstract class containing an instance of a HashMap? [closed]

java,polymorphism,instantiation,abstract
I believe that abstract classes cannot be instantiated. However, I have a HashMap instance inside my abstract class that I want to retrieve objects from. Is there any way possible to do this? Any insight would be appreciated, thanks in advance! Edit: I am actually looking for a way to...

Cant declare a QWidget because virtual functions are pure

c++,qt,function,virtual,abstract
I'm trying to make use of interfaces in Qt/C++, but I keep getting a compile error which makes no sense to me, because I have implemented the virtual functions in the derived class. So I was hoping for some help :) Oh yeah, and the compile error is "cannot declare...

why it is required to add abstract keyword in front of abstract methods

java,oop,abstract-class,abstract
This could be a useless question, Just out of my curiosity. Why we are forced to add the keyword abstract in front of abstract method of abstract class, when we don't need to add the keyword in case of interface. The possible answer could be: As abstract class are mixed...

How to instantiate class with nested abstract field with Jackson?

java,json,jackson,abstract
I've got following classes : public class City { Zoo zoo; } public class Zoo { Animal[] animals; } public abstract class Animal { String name; abstract void eat(); } I want to deserialize an instance of City class with Jackson. Howerer, since Animal is an abstract type, I've got...

How to use static abstract class as a callback in Java?

java,android,static,callback,abstract
I'm trying to figure out how I can use a static abstract class as a callback. I'm looking at Android's documentation here and here. The first link is a CameraManager which has a method called openCamera. This method requires an instance of the static abstract callback class StateCallback. My main...

why to choose abstract(without default implementation) over interface vb.net?

.net,interface,abstract
I am confused between Interfaces and Abstract classes I know the technical differences between them like interfaces can’t have fields while abstract can, also interfaces apply the multiple inheritance while abstract classes can’t. I am wondering if I have an abstract class with 4 methods but without default implementation, and...

Concrete Methods in Interface Classes

php,class,oop,interface,abstract
I am building some classes (in PHP, although this question extends to other OOP languages as well) which hold information from a database. As such, I want to create an Interface: "syncable". interface syncable{ protected function _pushToDB(); protected function _pullFromDB(); } The problem I am encountering is that I want...

AngularJS ui-router abstract state with second child

angularjs,angular-ui-router,state,abstract
I have a problem to load second child of state. Url is changed, but page not loading. .state('app', { abstract: true, template: '<ui-view/>', controller: 'myControl', data: { requireLogin: true } }) .state('app.CarsList', { params: { id: ':id' }, url: '/Companies/:name', templateUrl: 'CarsList.html', }) .state('app.CarsList.CarInfo', {// second child url: '/Info', templateUrl:...

Why does Python allow abstract methods to have code?

python,abstract
Why does python allow one to have code inside an abstract method? I know we can invoke that code through super, but I am not able to think of reasons why would I want my abstract method to have code in it.