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
1 answer

Java Collection Type Parameter to array

I want to create a helper method which gets Collection type parameter to return a list. This is what I have now: public class Helper { public static T[] CollectionToArray(Collection collection) { return…
KimchiMan
  • 4,836
  • 6
  • 35
  • 41
2
votes
1 answer

Abstract method implementation in component has undefined dependencies

Abstract class: export abstract class LanguageChangeAware { private sub: Subscription; protected language: string; protected constructor(protected eventService: EventService) { this.sub = eventService.getLang().subscribe(lang…
2
votes
1 answer

How using object pointer with dynamic array

Hello I'm studying c++ language and I'm really wondering that if use object Pointer with dynamic array. Weapon class is derived by CItem class. At this time I'm typing like this. CItem* pItem = new cWeapon[m_size]; and I doing initialize each…
James Park
  • 23
  • 3
2
votes
0 answers

An abstract subclass of OrderedDict? python3

A subclass that subclasses ABC and OrderedDict does not act as a true abstract class: >>> from abc import ABC, abstractmethod >>> from collections import OrderedDict >>> class AbstractOrderedDict(OrderedDict, ABC): ... @abstractmethod ... …
Asker
  • 105
  • 8
2
votes
3 answers

Do i need to implement all the methods of interface again while inheriting abstract class in Java?

I am trying to extends an abstract class which is implemented one method of interface so in my subclass i am trying to implement rest of the methods declared in interface but sub class forcing me to declare all the methods of interface, please help…
user10100235
2
votes
1 answer

should abstract class return same type as expected implemented method?

I am using Python abc package to declare abstract classes. When I define an abstract method, should I return an empty object with same type as expected or simply pass? MWE: import abc class A(abc.ABC): @abc.abstractmethod def…
ClementWalter
  • 4,814
  • 1
  • 32
  • 54
2
votes
0 answers

DLL exported class: Abstract base class and pimpl?

I was looking into creation of DLL's using C++ lately and stumbled by accident into the discussion of "Abstract Base Classes vs. Pimpl Idiom" when it comes to ABI compatibility. I'm pretty new to dealing with DLLs so please be patient if I get a…
Rafael Pasquay
  • 328
  • 4
  • 11
2
votes
2 answers

python - non-abstract method calls abstract methods

I have an example below: The first script where I define the abstract class: # test.py from abc import ABCMeta, abstractmethod class A: __metaclass__ = ABCMeta def __init__(self, a): self.x = a self.y = 0 …
scmg
  • 1,904
  • 1
  • 15
  • 24
2
votes
1 answer

Using By in POM - Selenium

I have been practicing using POM design approach (with Data Driven & testNg framework) for Selenium; I recently got to see a selenium automation developer using POM with neither @FindBy nor PageFactory in the script What I didn't understand using…
Vijayrushi
  • 41
  • 3
2
votes
3 answers

Does a pure virtual destructor suffice to make a class abstract?

I hope this is not becoming a 'duplicate', as there are so many questions about (pure) virtual destructures (yes, I do know about them). I want to build an 'interface' (-> abstract class) with a bunch of methods, which can be reimplemented, but…
ultrakult
  • 27
  • 1
  • 9
2
votes
1 answer

Typescript - call abstract method from abstract constructor or provide equivalent functionality

In Typescript - abstract methods cannot be called from within abstract constructors (the code will compile, but will crash at runtime). Take the following example where the code crashes: abstract class Puzzle { addState = () => { …
Foobar
  • 7,458
  • 16
  • 81
  • 161
2
votes
1 answer

c++ why return a reference to a base abstract class

In the class below there is a pointer model_ of type OpModel which is a class. This pointer is initialized in the constructor using new to create an OpModel object. That's fine, you have a pointer to a valid object. The method model() deferences…
ariane cathal
  • 85
  • 1
  • 6
2
votes
2 answers

Rails 3 Abstract Class vs Inherited Class

In my rails 3 model, I have two classes: Product, Service. I want both to be of type InventoryItem because I have another model called Store and Store has_many :InventoryItems This is what I'm trying to get to, but I'm not sure how to model this…
2
votes
1 answer

Constructor with values from inherited abstract class, which implements an interface

I am trying to instantiate objects of type Car through a constructor and I receive the following 2 errors: "The static field Vehicle.name should be accessed in a static way" and "The final field Vehicle.name cannot be assigned" on the constructor…
extra8
  • 67
  • 11
2
votes
4 answers

Why in both the code snippets '@Override' annotation work properly?

Although the class B implements the interface A, it does not provide the implementation of the method show(). Again, D extends C but in class D the implementation of displayNothing() is the same as the implementation of displayNothing() method in…