FAQ Database Discussion Community


How do you implement a Java Enumeration Abstract class and interface?

java,inheritance,enums,abstract-class
I have the following problem. I have a package with different enumeration classes in java. What is the correct approach to avoid repeting myself when adding new methods that are common to all enums? My problem: channel.java public enum Channel { channel1, channel2; } color.java public enum color{ color1, color2;...

Overload abstract methods in abstract class

java,inheritance,abstract-class,method-overloading,abstract-methods
I want to have an abstract class that has an abstract method, say abstract void compare(). But the parameters it takes should vary according to different implementations in different subclasses. I wonder what is the right way to do this? I cannot overload it by writing different signatures of it...

Abstract base class has abstract nested class [closed]

c++,iterator,abstract-class,nested-class
My code structure is as follows. I have a base abstract class which also has a nested abstract iterator. I inherit from the base class and i also inherit from the abstract base inherited class. To allocate the objects I use polymorphism: i am getting errors like: In file included...

Is there a way to force a derived class to implement an abstract class or an interface nested in base class?

c#,inheritance,interface,override,abstract-class
I have this abstract class: public abstract class Task { public string ID {get; set;} public string Name {get; set;} public abstract class Options{}; public abstract void Execute(); } I have other classes extending this class: public class Copy : Task { public override void Execute() { Console.Write ("running"); }...

Creating a generic / abstract “DBContext” Class for shared functionality among different DBs

c#,database,generics,inheritance,abstract-class
I am working on a C# project that is pulling data from SQL Server, ODBC data-sources and Oracle Databases at different times. At this point, I have created 3 different classes - Once for each type of DB access. However, I am seeing that 95% of the code is identical...

Can you force classes inheriting from abstract base class to only have the public methods defined in base case?

c++,c++11,inheritance,abstract-class
Is it possible to have an abstract class but FORCE implementing classes to have only the public methods that are in the abstract class? I don't care how the private methods work, but I want to force the classes to have only one public method. For example, say I have...

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 {...

Python Abstract Proper Way of Calling Library Imported in Base Class

python,python-3.x,abstract-class
What is the proper way of utilizing functions that are imported in the base class of an abstract class? For example: in base.py I have the following: import abc import functions class BasePizza(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod def get_ingredients(self): """Returns the ingredient list.""" Then I define the method in diet.py:...

Is an Abstract Class the same thing as a Base Class?

c++,oop,abstract-class,base-class,abstract-base-class
Is an Abstract Class the same thing as a Base Class? I occasionally see the term Base Class, but when I look up what it means, I tend to see "Abstract Class" thrown around. Are they just two words that mean basically the same thing?...

operator overloading in abstract class(interface)

c++,interface,operator-overloading,abstract-class
I want to have an abstract class IMatrix which contains pure virtual members and one of them is an operator overloading member. template <typename T> class IMatrix { public: virtual T operator+(const T& b)=0; }; and for the implementation I want to use a third party matrix class as for...

How to extract variable from one function into another in same class in php

php,oop,abstract-class
I want to use variable value from one function into another function of same class. I am using abstract class using which I am declaring variable as global indirectly. I can not declare variable as global in the class. My demo code is as follows: <?php abstract class abc {...

Is there any way to subclass a C# interface in a way that *restricts* behavior?

c#,inheritance,interface,abstract-class
public interface IBlackBox<T> { bool IsValid(); T GetValue(); } public abstract class Box<T>:IBlackBox<T> { public bool IsValid() { return true; } public abstract T GetValue(); } A Box produces a value on demand; could be an on-demand computation, or random, or just a fancy nullable, etc. A BlackBox does the...

Does the JVM internally instantiate an object for an abstract class?

java,abstract-class,object-construction
I have an abstract class and its concrete subclass, when I create an object of subclass it automatically calls the super constructor. Is the JVM internally creating an object of the abstract class? public abstract class MyAbstractClass { public MyAbstractClass() { System.out.println("abstract default constructor"); } } public class ConcreteClass extends...

How to correctly handle a list made of generic classes with methods that also have generic returns

c#,json,generics,interface,abstract-class
I believe this question is answered simply, but since I've been banging my head on this issue for a while, I've might have trouble seeing the overall picture. I want to load multiple files (in this case, JSON), so I created a DataLoader class that will handle this. In this...

Can an abstract class be mocked using mockito?

unit-testing,junit,mocking,mockito,abstract-class
In a class under test, if its constructor takes in an abstract class parameter can we mock it using mockito? Ex public abstract AbstractClass{ } //Class under test public class SourceClass{ SourceClass(AbstractClass abstractClass){} } @RunWith(MockitoJUnitRunner.class public SourceClassTest{ @Mock AbstractClass abstractClass; } whenever I do this i get this error java.lang.ExceptionInInitializerError...

Class organization to access abstract method from Android fragment class

java,android,android-fragments,abstract-class,abstract-methods
I'm not really sure what my problem statement is, as you can tell from the title. I have an abstract class A that extends Activity. Class A has an abstract method defined: public abstract class A extends Activity { ActionBar.Tab devicesTab, otherTab; Fragment fragmentTab = new FragmentTab(); protected abstract void...

C++ make an object whose type is an abstract class

c++,abstract-class,pure-virtual
I am trying to make a system like Java's swing, where you have a window, and that window has multiple components, such as Labels (text/images), Text Boxes, Check Boxes, etc. The way swing works is that there is a Component class, which is abstract, which has an abstract paint method,...

Interface, abstract class, and the implementation

java,interface,naming-conventions,abstract-class,java-api
In java I often find myself implementing the List interface instead of, for example, extending the AbstractList class. This is rather common in the Java API (and in many third-party libraries I've looked at), that there exists an interface and an abstract class for that interface. Why is this? Why...

Abstract class using IComparer

c#,compare,abstract-class,icomparer
I want to create and abstract class A that implements IComparer so that I can implement different forms of comparing in the subclasses and later on do: A sortBy = new B(); A sortBy2 = new C(); I'm new in C# and I don't quite get how to do that....

Why do I have to use an import in my subclass, when it's already in the superclass?

java,abstract-class
I have two questions. I have an Apple class that extends an abstract Fruit class see code below ↓ First question: Why do I have to use the import java.awt.Color; in my apple class, since it's already in my Fruit class? I get an error: cannot find symbol Second question:...

C++11 vector of smart pointer

c++,c++11,abstract-class,smart-pointers
Suppose we have the following codes. We have following classes Animal as AbstractClass Dog and Bird which is subclass of Animal Zoo which keeps all animals _ class Animal { public: Animal(); void HasWings() = 0; }; class Bird : public Animal { public: Bird() : Animal() {} void HasWings()...

Can I extend Iterator to allow access to encapsulated inner class fields?

java,iterator,abstract-class,inner-classes,extends
I'm frustrated, trying to add methods to a custom iterator. For an assignment in my second quarter Java class, we are supposed to implement, from scratch, a linked list. No problem: I have created an outer class to implement the linked list and a static private inner class to implement...

Int value does not change after calling method [closed]

java,abstract-class,implements
After calling doReading(),the value of pages is supposed to change, but it does not. Is it possible to do this without declaring int pages; in the MyMath2 and MyScience2 classes. The output should be something like: Before reading: Math- must read 5 pages After reading: Math- must read 3 pages...

Using static function in extended class in PHP

php,class,object,abstract-class,static-methods
I have an abstract class that has a method which uses a static function. This static function is defined in sub-classes and is different for each sub-class. Which sub-class will be used to create object is determined in the script. See super simplified code below: abstract class fooClass implements iFooClass...

Java: Abstract Class Invocation via Main Method

java,abstract-class
Okay, people are probably going to run to flag this as a duplicate, just by reading the title and without really reading the question. So please know that I HAVE tried to look at other questions on this platform, but have not found something that clears my doubts exactly. Kindly...

Error in overriding image property of ImageView

ios,iphone,uiimageview,uiimage,abstract-class
I am trying to override getter of ImageView to return placeholder image if imageView not settled, But I have error and I can not do it. Why this happens and how can I solve this problem? My code @implementation OvalImageView - (UIImage *)image { return _image? _image : [UIImage imageNamed:@"avatar-big-placeholder"];...

abstract class implements Cloneable; abstract Object clone()

java,clone,abstract-class
Lets say I have this class: public abstract class AbstractFoo implements Cloneable { public abstract Object clone(); } And the subclass: public class Foobar extends AbstractFoo { @Override public Object clone() { try { Foobar c = (Foobar) super.clone(); /* some operations */ return c; } catch (CloneNotSupportedException e) {...

Function signature returning abstract class

c++,abstract-class,language-lawyer,signature
Consider some abstract class A: class A { virtual void f() = 0; }; Suppose I wish to declare a function signature type returning this class: using Type = A(); Given this code, gcc-4.8.2 failes with error error: ‘type name’ declared as function returning an abstract class type clang-3.3 compiles...

Library system in Java

java,abstract-class
I read this task and I am confused as to how I should start it because I don't fully understand sub classes :(. Can someone help me get started with the code? Thank you :). The Task: Create an abstract class Book with two subclasses: Fiction and NonFiction. NonFiction should...

Abstract class using an interface impleented in subclass?

vb.net,oop,object,interface,abstract-class
I have an idea that uses both an abstract class and an interface, but i'm not sure if its possible to do what I am thinking of and how. I have an abstract class modeling a device, containing only abstract functionality. When implemented this class basically serves as a driver...

How can I find out which method of a derived class is not implemented?

c++,visual-studio-2010,inheritance,abstract-class,pure-virtual
I have an abstract base class, where some functions are implemented and some are purely virtual. From this base class, I have created a derived class which implements all virtual functions. However, it still complains that the derived class is abstract. I assume that I have forgotten to implement one...

Using abstract screen in LibGDX

java,android,libgdx,abstract-class
I want to use an abstract screen for my LigGDX game. I have read many websites and many of them use abstract screen only to group the common codes (e.g. common methods) together. If this is the case, we can simply use a normal class to do the task. The...

Abstract Class with Generic Subtype

c#,.net,generics,override,abstract-class
I implemented an abstract class like the following: public abstract class Pack { protected List<PackEntry> m_Entries; public Int32 EntriesCount { get { return m_Entries.Count; } } public Pack() { m_Entries = new List<PackEntry>(); } #region Methods: Abstract ... #endregion } public sealed class PackTypeA : Pack { ... } public...

Is it possible to use parentclass when it's abstract

c++,abstract-class
I'm using capd library (http://capd.ii.uj.edu.pl/) and I have two pieces of code: C0Rect2Set set(ex.start); timeMap(ex.time, set); and C0HOTripletonSet set(ex.start); timeMap(ex.time, set); I'd like to abstract on the type of C0Rect2Set and C0HOTripletonSet. I think that both C0Rect2Set and C0HOTripletonSet are deriving from C0Set (I'm not sure about this, but that...

Please explain the difference between abstract class VS concrete class?

java,abstract-class
I have one abstract class with two unimplemented (abstract) methods, one implemented method and one static method like below code. public abstract class AbstractClass1 { static void test(){ System.out.println("111"); } public abstract void test2(); public abstract void test3(); public void test4(){ System.out.println("222"); } } I am extending this class in...

Polymorphic function in class which is implementing abstract class

c++,abstract-class
class Eq { public: virtual bool operator==(Eq operand) = 0; }; class Day : public Eq { public: enum DAY { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } day; Day(DAY init_day) : day(init_day){} bool operator==(Day operand) { return day == operand.day; } }; int main() { Day d1(Day::Monday); Day...

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...

Overriding toSting in derived class

c#,override,abstract-class,tostring
I have an abstract class Animal Looking like this abstract class Animal{ protected int numberOfPaws; public abstract String speak(); public String toString(){ return "I have " + numberOfPaws + " paws"; } } Then I have a derived class that has a new implementation of toString() looking like this class...

What is the difference between inherit from an abstract class and from a concrete class? Why would we need the latter?

class,inheritance,design,abstract-class
I Know Abstract is a class something else extends on but why would anything want to extend a non-abstract class? Is it generally a better convention to only extend from abstract classes as then they cant be instantiated so it doesn't do weird stuff? an example of both showing why...

C++11 alternative to the Java anonymous callback class

java,c++,c++11,callback,abstract-class
I realise that the solution I have here is far from ideal with C++, so I'm asking what a proper C++ programmer would do in this situation. (C++11) I have a DialogBox class, which stores a collection of buttons. At the moment I have a pure abstract inner class DialogBox::Button...

Abstract Views for API level

java,android,layout,abstract-class
So currently I have a view <TextureView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/texture_view" android:visibility="gone" /> Which only supports Android API 14 and up ... I want to create a different view for API < 14 ... So I want create an abstract view and call it in the XML layout file <CustomView android:layout_width="match_parent"...

How to capture type of a local variable inside a lamda expression in linq

c#,linq,lambda,closures,abstract-class
I found some duplicate code today and would like to reduce it to one method. In order to do it, I'd like to inject something more abstract into the lambda here: public IEnumerable<AbstractFoo> GetMatchingFoos() { return IEnumerable<AbstractFoo> exactMatchFoo = exactMatchList .Where (d => d is RedFoo); } //Horrifying duplicate code!:...

How to implement java template method design pattern for image objects: BufferedImage, Image, ImageIcon [closed]

java,class,design-patterns,methods,abstract-class
What would be an example of template method design pattern for image objects, or different types of image like: BufferedImage, Image, ImageIcon. I only need java class methods and their signatures and fields i don't need real functional code. this would be based on the fact that different types of...

How to handle return of Abstract Objects

c++,pointers,reference,abstract-class,return-value
I'm facing the following situation: class Base{ virtual void Stuff() = 0; }; class ConcreteA : public Base{ void Stuff() {}; }; class ConcreteB : public Base{ void Stuff() {}; }; class Context { Base exec() { ConcreteA conc_a(); return a; } }; Of course the compiler gives me an...

How to access the class variable of abstract class in non abstract class?

java,abstract-class
I have abstract class which is having a variable at class levele.Now i want to use this variable in other class.How can i achieve it? Following is my code public abstract class MyClass { String name="John"; } ...

How do I implement abstract class inside abstract class in the implementation class in Java?

java,inheritance,abstract-class
I have two classes which have structures look like the following code. public class ClassOne { private Data data; public ClassOne(Data data) { this.data = data; } public Data getData() { return data; } public static class Data { //code one } } public class ClassTwo { private Data data;...

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...

Is it the best option to convert a java interface with static fields in a abstract class in c#?

java,c#,interface,field,abstract-class
public interface IHashStorage<T> { public static final float INITIAL_LOAD_FACTOR = 0.7f; public static final int INITIAL_CAPACITY = 149; } I have the code above which needs to be translated in c#. The only solution that seems to be proper is to make it an abstract class.From what I found it's...

What is the difference between these two c# abstract classes? [closed]

c#,abstract-class,object-oriented-analysis
So I was following a c# tutorial the otherday (still a begginer) and I saw how the class ATMState was defined: public abstract class ATMState { private ATM atm; public ATM Atm { get { return atm; } set { atm = value; } } private int dummyCashPresent = 1000;...

Inheritence of c'tor and d'tor from abstract base through other abstract classes into concrete

c++,inheritance,c++11,clang,abstract-class
Main Question I am trying to build a clang plugin as per the instructions here, but I am encountering linker errors when I try to build. These are the errors: /tmp/Test-1ea47e.o: In function `ASTFrontendAction': /usr/lib/llvm-3.4/include/clang/Frontend/FrontendAction.h:216: undefined reference to `clang::FrontendAction::FrontendAction()' /tmp/Test-1ea47e.o: In function `~TestPlugin': /home/path/to/plugin/Test.cpp:12: undefined reference to `clang::FrontendAction::~FrontendAction()' /tmp/Test-1ea47e.o:(.data.rel.ro+0x20): undefined...

Get Namespace of an object using an Abstract Class or Trait?

php,oop,namespaces,abstract-class,trait
I have some code such as the following: namespace { trait ns{ public function get_ns(){ var_dump(__NAMESPACE__); } } } namespace a{ class obj{ use \ns; } } namespace b{ class obj{ use \ns; } } namespace { $a = new a\obj; $b = new b\obj; $a->get_ns(); $b->get_ns(); } Both $a->get_ns();...

Nested abstract class in an abstract class and how to implement it

c#,abstract-class,inner-classes,abstraction
I have an abstract class A and a abstract method with a parameter which is again abstract class B defined in the same abstract class A. When I extended this abstract class A as apart of another class C how can I implement the method with parameter of nested abstract...

Interface, Abstract Class and Methods of Abstract Class

java,oop,interface,abstract-class,late-binding
I am learning how to use the Factory pattern for creating objects in Java. I want to create classes to manage Cars. A car can either be small or large. I created an interface that defines the methods to be implemented by an implementing class. An abstract class implements some...

Pointer to function taking abstract parameter

c++,abstract-class,function-pointers
Let A be an abstract class in C++: // legal class A { virtual void m() = 0; } It is illegal, of course, to define a variable whose type is an abstract class: A a; // illegal Indeed, clang 3.6.0 complains thus: wat.cc:5:3: error: variable type 'A' is an...

Factory method of IntBuffer (and other primitive type buffers) return instance but those classes are actually defined abstract

java,abstract-class,factory-method
abstract class IntBuffer seems like you can't create an instance of this class anyway , because its declared abstract but at the same time , there's a static factory method IntBuffer allocate(int capacity) and now you can create an instance by simply Buffer b=IntBuffer.allocate(128) but wait, IntBuffer was abstract and...

Abstract class return in interface

java,abstract-class
First of all, pretty new in java, sorry if it is a simple question. I have implemented an abstract class, and two classes that extends it. public abstract class Lado{ //body } and the two other classes with this form for example public class Arista extends Lado { //body }...

When to use DI over abstract inheritance?

c#,dependency-injection,abstract-class
I am designing a class that uses an abstract property to provide a point of access to a field. Here is a snippet of my code: public abstract class PageBroker : WebBroker { public abstract IPageProvider Provider { get; } } public class ArticleBroker : PageBroker { public override IPageProvider...

Refactoring a concrete method in abstract class which contains an abstract method

c#,design-patterns,refactoring,abstract-class
Considering the below code, abstract class AbstractClass { public abstract void AbstractMethodA(); public void ConcreteMethodA() { //Some operation ConcreteMethodB(); } } public void ConcreteMethodB() { //Huge code unrelated to this class AbstractMethodA(); } } class DerivedClass : AbstractClass { public void AbstractMethodA() { //Some operation } } Now I wish...

Subclass of an Abstract class, always call Abstract constructor

c#,constructor,abstract-class
I have an abstract class and a child class abstract class abstractClass { public int x; protected abstractClass(int x) { this.x = x; } } class childClass : abstractClass { childClass(int x) : base(x) { } } I have many child classes like this one, where all of those classes...

Java Set, Abstract class extends itself?

java,set,abstract-class
I am doing a project based on Set in Java, I have given a exiting project as a base. I have found the following code but could not understand what it means particularly an AbstractClass Extends itself. Any help would be appreciated. Thanks public abstract class AbstractClass<I extends AbstractClass<I, V>,...

Java alternative for empty overridden method in sub class

java,android,inheritance,abstract-class
I have the following class hierarchy: BaseActivity: public abstract class BaseActivity extends AppCompatActivity { protected abstract void bindView(); } ASubActivity: public class ASubActivity extends BaseActivity { @Override protected void bindView() { //No implementation } } BSubActivity: public class BSubActivity extends BaseActivity { private Toolbar toolbar; @Override protected void bindView() {...

Python Abstract Method With It's own __init__ function [duplicate]

python,python-3.x,abstract-class
This question already has an answer here: Python, invoke super constructor 3 answers How can I define a __init__ function in both the base and derived abstract classes and have all self.* be available in the abstract method? For example: What is the proper way of utilizing functions that...

C++ Abstract Class error on Constructor in Qt 5

c++,constructor,abstract-class,qt5
I'm creating a simple abstract class named Asset, the header code looks like this: #ifndef ASSET_H #define ASSET_H #include <QString> #include <QDate> class Asset { public: Asset(QString des, QDate dat); ~Asset(); virtual QString toString(); virtual double value(); QString getDescription(); private: QString description; protected: QDate date; }; #endif // ASSET_H This...

How to force a class to declare a final variable?

android,abstract-class,final
For the moment, I created an abstract class like this: public abstract class MyClass { public final static String TAG; ... } But it gives me an error of not initializing a final variable. Then I tried to initialize it from a constructor, but it didn't work either (gives the...

Why are interfaces helpful?

java,interface,abstract-class
I know exactly what are the differences between Interfaces and Abstract classes, but why are Interfaces helpful? look at this : ...

Netty: Bound Mismatch

java,abstract-class,netty,nio
I am new to java and was trying to use Netty to build a sample tcp server. Here is what i have currently package http_server; import java.net.InetSocketAddress; import java.nio.channels.SocketChannel; import netty_tutorial.EchoServerHandler; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.ServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;...

Abstract methods not-implemented error is not being thrown

java,inheritance,abstract-class
So i was just trying to learn java coming from a C++ background, as part of a quick ramup I just implemented a base class from a abstract class as below abstract class my_abstract_class { abstract void my_abstract_function(); } class my_concrete_class extends my_abstract_class { } public class ConcreteClasses { public...

reading fields which have null value

java,arraylist,override,abstract-class
I have an abstract class "Homework"and 4 other classes that extend it (I only pasted one of them since they are identical). The program compiles, but the output looks like this: null - must read 0 pages null - must read 0 pages null - must read 0 pages null...

Java interfaces and type polymorphism, one implement vs extend

java,interface,polymorphism,abstract-class
So this is more of a question of curiosity rather than needing an issue solved, I think. So I am sitting with AndEngine for Android in Android Studio and I want to make a AudioManager to handle all my audio, as a start. I could implement AndEngine's interface called IAudioManager...

Cannot access an Object Reference instantiated by a sibling class

java,inheritance,nullpointerexception,abstract-class
I have an abstract class that declares a number of object references, specifically a JLabel. I have two classes that both extend that class. One of the children instantiates the JLabel and calls a couple of its methods. That classes sibling attempts to call the setText method on the JLabel...

Template operator returning a reference to an abstract class

c++,templates,operators,abstract-class
Fellas, why won't this code work? template <typename t> class Abstract { public: ~Abstract(){} virtual Abstract<t>& operator +(Abstract<t>&) = 0; }; template <typename t> class Not_Abstract : public Abstract { t* tab; //let Not_Abstract store an array of objects of type t, whatever public: ~Not_Abstract(){ delete[] tab; } Not_Abstract<t>& operator...

Why can an abstract class force a concrete method to be overridden?

java,abstract-class,method-overriding
I use a library where an abstract class overrides a concrete method inherited from Object with an abstract method: public abstract class A { @Override public abstract boolean equals(Object obj); } To extend this class, I have to implement the equals method: public class B extends A { @Override public...

How to override __getitem__ when it's a class method?

python,abstract-class
class Custom(type): @classmethod def __getitem__(cls, item): raise NotImplementedError("") @classmethod def test(cls): print("class custom : test") class Book(metaclass=Custom): Note = 0 Pad = 1 Name = { Note : "Note", Pad : "Pad"} @classmethod def __getitem__(cls, item): return Book.Name[item] @classmethod def test(cls): print("class book: test") My intention is to have Book[Book.Note]...

Pass an instance of a class deriving from a base class into a function

c++,class,inheritance,abstract-class
I have a class hierarchy in my C++ program: class DEBase { public: virtual double distance(vec3) = 0; }; class Sphere : public DEBase { private: ... public: Sphere(...) {...} ... double distance(vec3 p) {...} }; class XZPlane : public DEBase { ... public: XZPlane(...) {...} ... double distance(vec3 p)...

If I extend an abstract class, that is implementing an interface, do I need to rewrite the methods?

java,interface,abstract-class,implementation
I have an interface with several methods. I then have an abstract class that defines some of those methods, but also leaves some of the methods abstract. Now I have a class that extends the abstract class. Do I need to write all the methods from the original interface and...

Force non-abstract method to be overridden

java,abstract-class
I have a method String foo() in an abstract class which already does a few precomputations but can't deliver the final result the method is supposed to return. So what I want is that each non-abstract class inheriting from my abstract class has to implement foo in a way that...

Why mark class abstract when there is no abstract method

java,oop,abstract-class
I am little confused about abstract class in java. I know that whenever there is an abstract method in the class compiler force developer to mark class abstract. But even we don't have any abstract method in the class we still mark the whole class as abstract. I am not...

Scala: access “static” member of bounded generic type

scala,abstract-class,abstract-type,bounded-types
I want to achieve the following: abstract class Super { def typeSpecific: Int } class SubA extends Super { def typeSpecific = 1 } class SubB extends Super { def typeSpecific = 2 } class Tester[T <: Super] { def test = T.typeSpecific } val testerA = new Tester[SubA] val...

Private constructor in abstract class Scala?

scala,abstract-class
I know that abstract classes can't be instantiated, so maybe I'm answering my own question, but is there a way to put a private constructor in an abstract class? My problem is I have an abstract class with two subclasses that have the exact same methods, and some of the...

How to instantiate a child singleton of an abstract class?

php,singleton,abstract-class
I have an abstract class and a child that extends the abstract class. The child is supposed to be a sigleton. Here is simplified example of the abstract class: abstract class AbstractClass{ protected static $instance = NULL; abstract protected function meInit(); private function __construct(){ $this->meInit(); $this->init(); } private function __clone(){}...

Remove dependency on inherited abstract class references

c#,.net,inheritance,abstract-class
I am trying to setup a scenario where we can create a common set of models for our workgroup and then implement or extend them if/when needed. I have the following setup: namespace Workgroup.DomainClasses { public abstract class WorkGroupOrder { private ICollection<WorkGroupItems> _items; protected WorkGroupOrder() { _items = new List<WorkGroupItems>();...

PHP Abstract Class Array Protected Properties

php,arrays,oop,properties,abstract-class
i'm somewhat new in using Abstract Classes and OOP so please bear with me. I'm trying to make a list of Employees and Customers but im running into a bit of trouble printing out the array of objects in my StoreList class since they are all protected. What i want...

Making change in Base Activity to reflect changes in All derived Activities?

java,android,inheritance,android-activity,abstract-class
I have a public abstract class BaseActivity extends Activity { protected void setCustomHeader(String title,String subText){ } } and two other Classes Extending the BaseActivity class. public class ListActivity extends BaseActivity { setCustomHeader("List","Child1"); } & public class DetailsActivity extends BaseActivity { setCustomHeader("Details","Child2"); } The BaseActivity generally reduces the code here of...

Null property value from Abstract class

c#,abstract-class
I would really appreciate any help with the following scenario that I'm working on and wasn't able to find a solution for. My apologies if the title does not match up with the current lingo too. The following code is an example that I'm working: public class SumObject { public...

Swift - mixing abstract and concrete methods

ios,swift,oop,abstract-class
Swift has no abstract classes and methods. Instead, it offers protocols. That's fine when your classes are either fully abstract or fully concrete. But what is the best 'Swift' way to implement an abstract class that also has concrete methods? Pseudo-code example: class Animal { abstract makeSound() abstract eyeCount() }...

Modelling a regular expression parser with polymorphism

java,regex,parsing,polymorphism,abstract-class
So, I'm doing a regular expression parser for school that creates a hierarchy of objects in charge of the matching. I decided to do it object oriented because it's easier for me to imagine an implementation of the grammar that way. So, these are my classes making up the regular...

Concrete subclass that does not override abstract methods from abstract class

java,abstract-class,method-overriding
Say that I have two, abstract methods in an abstract base class: protected abstract void writeData(OutputStream stream); protected abstract void writeData(Writer writer); When I make an implementation, I have to override these methods so that when the data needs to be written, it knows how to do it. What I...

i need to pass rectangle type of variable to function which is in interface

c#,interface,abstract-class
public class QuadTree<T> where T : IHasRect { private List<T> m_objects = null; // The objects in this private Rectangle m_rect; // The area this // Getters and Setters public List<T> Objects { get { return m_objects; } } public Rectangle Rect { get {return m_rect; } } public QuadTree(Rectangle...

Abstract classes and PyMongo; can't instantiate abstract class

python,python-3.x,abstract-class,pymongo
I created the empty abstract class AbstractStorage and inherited the Storage class from it: import abc import pymongo as mongo host = mongo.MongoClient() print(host.alive()) # True class AbstractStorage(metaclass=abc.ABCMeta): pass class Storage(AbstractStorage): dbh = host def __init__(self): print('__init__') Storage() I expected the output to be True __init__ however, the one I'm...

abstract private inner class

java,abstract-class,private,inner-classes
I am preparing for an Oracle examination and answered incorrectly to the following question: the combination abstract private is legal for inner classes As it turns the answer is true, I answered false, as I could not find any use cases for having an abstract private inner class, that cannot...

Java creating new object

java,arrays,object,abstract-class,copy-constructor
I have an abstract class Specie, and then class Animals which extends species, and then my classes for animals (e.g. Sheep). In Animals I have a method which checks if two objects are on the same position on the map, and if the are the same type (e.g. Sheep and...

writing good abstract classes in java

java,abstract-class
I have the following need and please help me to write good and abstract class. Different types of operations is needed based on the type I have a abstract class, abstract public class FileHelper{ //Template method //This method defines a generic structure for parsing data public void parseDataAndGenerateFile(String fileDownloadType) {...