Questions tagged [abstract-class]

Abstract classes are classes which cannot be instantiated. They exist to provide common functionality and interface specifications to several concrete classes.

Abstract classes are classes which cannot be instantiated. They exist to provide common functionality and interface specifications to several concrete classes.

From Abstract Type on Wikipedia:

Abstract classes can be created, signified, or simulated in several ways:

  • By use of the explicit keyword abstract in the class definition, as in Java, D or C#.
  • By including, in the class definition, one or more methods (called pure virtual functions in C++), which the class is declared to accept as part of its protocol, but for which no implementation is provided.
  • By inheriting from an abstract type, and not overriding all missing features necessary to complete the class definition.
  • In many dynamically typed languages such as Smalltalk, any class which sends a particular method to this, but doesn't implement that method, can be considered abstract. (However, in many such languages, the error is not detected until the class is used, and the message returns results in an exception error message such as "does Not Understand").
5262 questions
2
votes
2 answers

Is the abstract method in the interface Inter is same with the abstract method in the abstract class Test?

When I declare the 'abstract public void show();' in the abstract class Test does that create a brand new show() method or just refer to the show() method declared in the interface Inter? Please clarify. interface Inter { void…
2
votes
2 answers

Scala abstract class instance

I am new to Scala. I have question about List class. This is an abstract and sealed class. It means cannot be instantiated, neither extended. So what is its usage? How can it be that something like following works? val myList = List(1,2,3) Would…
toto'
  • 1,325
  • 1
  • 17
  • 36
2
votes
2 answers

Why abstract class cannot have Sealed method

Code Snippet 1 (Compilation Error) - A.M2() cannot be sealed because it is not an override abstract class A { public abstract void M1(); public sealed void M2() { // Do Something } } Code Snippet 2 (Works Fine) abstract…
Mrinal Kamboj
  • 11,300
  • 5
  • 40
  • 74
2
votes
2 answers

Proper way to implement ABC SubClass

I have an Interface class which defines the requirements to an active "in-use" class: class Portfolio(ABC): @abstractmethod def update_portfolio(self): raise NotImplementedError @abstractmethod def update_from_fill(self): …
mfvas
  • 115
  • 1
  • 11
2
votes
2 answers

Class is not abstract and does not override abstract method in superclass

I am working on a generic implementation of the Genetic Algorithm. I'm trying to extend a specific Individual for the knapsack problem from the abstract class Individual package GenericGA; public abstract class Individual { private double…
GioGio
  • 448
  • 2
  • 5
  • 22
2
votes
1 answer

Can I use lambda expression to replace instantiating an abstract class with only one abstract method?

(This question is asked under an Android context, but answerable with only Kotlin knowledge.) (Also, I found some answers in SO regarding same question in Java8 Lambda, but I can't find one regarding Kotlin.) Like many people do - I am now using…
Sira Lam
  • 5,179
  • 3
  • 34
  • 68
2
votes
4 answers

Calling methods of class derived from an abstract class [C++]

You'll have to forgive me if this is a really basic question; I haven't used C++ this much in a long time so I've forgotten how a lot of it works. Anyway, I have a base class and a couple derived classes like this (super oversimplified, but the gist…
Andrew
  • 4,953
  • 15
  • 40
  • 58
2
votes
2 answers

Why ZEND uses interfaces and abstract classes everywhere while Codeigniter doesn't use them at all?

ok. So i grep'ed through Codeigniter 2.0 directory looking for interface or abstract keywords. I couldn't find Codeigniter using class skeletons anywhere. AFAIK and can see - CI only uses concrete class implementations. Is not using abstracts and…
Stann
  • 13,518
  • 19
  • 65
  • 73
2
votes
1 answer

Diamond inheritance in Java with abstract classes

I have an assignment with several abstract classes and including inheritance, but I've got a problem in a specific place of the assignment. This is what I have (close up to the specific place where the problem going to happen): public abstract class…
2
votes
3 answers

C++ pure virtual functions implementation in derived class

I have a top API (based on abstract class) which is composed by a base API (that will be reused by different top APIs). class api_base { public: virtual int foo() = 0; }; class api_top : public api_base { public: virtual int bar() =…
2
votes
1 answer

Specifying method with interface parameter

I spent some time learning how "Event Sourcing" works and how one would implement that in C# and i got stuck at some point. As it is very difficult to describe my problem without code I'll first give you a simplified version of my code. I removed…
Alex B.
  • 21
  • 3
2
votes
1 answer

Pure Virtual Method VS. Function Pointer

Recently I've been designing a Thread class library, I've made a Thread abstract class like the following: class Thread { public: run() { /*start the thread*/ } kill() { /*stop the thread*/ } protected: virtual int doOperation(unsigned…
Josef
  • 353
  • 1
  • 2
  • 8
2
votes
2 answers

Why can't we make Cloneable as an absract class instead of making it as an interface?

Why can't we make Cloneable as an absract class instead of making it as an interface ?
SHIVA
  • 21
  • 2
2
votes
1 answer

I have an abstract class and two extensions, can I have a common mapper?

In my project I have the following model: public class Object1 extends ObjectBase { private Value1 specific1; } public class Object2 extends ObjectBase { private Value2 specific2; } public abstract class ObjectBase { private String…
2
votes
7 answers

When some methods will not be used/not implemented, use an Interface or Abstract Class?

I have a project where quite a few functions and variable getters will be defined, abstractly. My question is should I use an abstract class for this(with each function throwing NotImplementedException), or should I just use an interface? Or should…
Earlz
  • 62,085
  • 98
  • 303
  • 499
1 2 3
99
100